home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / shell / 5513 < prev    next >
Encoding:
Text File  |  1993-01-28  |  1.9 KB  |  59 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!tcsi.com!iat.holonet.net!news.cerf.net!usc!cs.utexas.edu!torn!nott!bnrgate!bcars267!bcars6f4!webster
  3. From: webster@bnr.ca (Brent Webster)
  4. Subject: Re: padding things out
  5. Message-ID: <1993Jan27.175539.17114@bnr.ca>
  6. Sender: news@bnr.ca (usenet)
  7. Nntp-Posting-Host: bcars6f4
  8. Reply-To: webster@bnr.ca
  9. Organization: Bell Northern Research Ltd
  10. References: <1993Jan26.194057.1884@unix.brighton.ac.uk>
  11. Date: Wed, 27 Jan 1993 17:55:39 GMT
  12. Lines: 45
  13.  
  14. In article 1884@unix.brighton.ac.uk, ndl@unix.brighton.ac.uk (Nathan Lock) writes:
  15. >How can I take a variable length field 
  16. >(e.g the gecos field in the password file)
  17. >and pad it out in a shell script so that it is always the same length 
  18. >for the next field to line up. 
  19. >(with a tab I will not always get the same column, sometimes I need 1,
  20. >other times 2 for a shortname) how can I determine whether I need 1 or 2 
  21. >in a shell script?
  22. >
  23. >e.g a single tab
  24. >
  25. >Fred Bloggs     next field
  26. >Joe Smith    next field
  27. >Samantha Smith-jones    next field
  28. >Sam Wheeler    next field
  29. >
  30. >what I want to achieve:-
  31. >
  32. >Fred Bloggs        next field
  33. >Joe Smith        next field
  34. >Samantha Smith-Jones    next field
  35. >Sam Wheeler        next field
  36. >
  37. >Standard shell or awk solutions please as I do not have perl etc.
  38. >
  39. >Awaiting you reply
  40. >
  41. >Nathan Lock.
  42. Try awk  ie
  43. % echo "biff stuff    junk"|awk -F"    " '{printf "%-30s %s\n",$1, $2}'
  44. biff stuff                     junk
  45.  
  46. where 
  47. echo "biff stuff<a tab>junk"|awk -F"<a tab>" '{printf "%-30s %s\n",$1, $2}'
  48. ---
  49. *************************************************************
  50. Brent Webster   (CoDesign Tools & Modelling)
  51.  
  52. Bell-Northern Research Ltd * Ph : (613) 763-4962
  53. P.O. Box 3511, Station C   * Fax: (613) 763-7742 or 2626
  54. Dept 9R12, MS103           * InterNet/NetNorth: webster@bnr.ca
  55. OTTAWA,Ont,Canada K1Y 4H7  * Bitnet: webster@bnr.ca.bitnet
  56. *************************************************************
  57. #include <std.disclaimer>
  58.  
  59.