home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / shell / 5520 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  1.5 KB

  1. Path: sparky!uunet!UB.com!pacbell.com!ames!agate!doc.ic.ac.uk!warwick!uknet!glasgow!unix.brighton.ac.uk!ndl
  2. From: ndl@unix.brighton.ac.uk (Nathan Lock)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: padding things out
  5. Message-ID: <1993Jan28.191331.18117@unix.brighton.ac.uk>
  6. Date: 28 Jan 93 19:13:31 GMT
  7. References: <1993Jan28.083829.20353@us-es.sel.de>
  8. Organization: University of Brighton, UK
  9. Lines: 29
  10.  
  11.  
  12. >How can I take a variable length field 
  13. >(e.g the gecos field in the password file)
  14. >and pad it out in a shell script so that it is always the same length 
  15. >for the next field to line up. 
  16. >(with a tab I will not always get the same column, sometimes I need 1,
  17. >other times 2 for a shortname) how can I determine whether I need 1 or 2 
  18. >in a shell script?
  19. >
  20. >No, use buildin things of sh(1). This runs much faster than the awk(1) example.
  21. >   while :
  22. >         do
  23. >              case "${field}" in
  24. >                  ??????????*)
  25. >                        break;;
  26. >              esac
  27. >              field="${field} "
  28. >         done
  29. >Now ${field} is at least 10 charcters long (the '*' at the end of ?????????? avoids infinite loops).
  30. >The above loop should pad field with the right number of spaces to make it 10 characters long. You can get unexpected results if field already containted more than 10 chars or some funny chars like tabs or newlines,...
  31. >Pawel Nabe                                   PaN Super Sonic Software Service
  32. >
  33.  
  34. Thanks to everyone who replied, this was the best solution as it does
  35. not rely on an external program.
  36.  
  37. Many thanks !
  38.  
  39. Nathan.
  40.