home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!tcsi.com!iat.holonet.net!news.cerf.net!usc!cs.utexas.edu!torn!nott!bnrgate!bcars267!bcars6f4!webster
- From: webster@bnr.ca (Brent Webster)
- Subject: Re: padding things out
- Message-ID: <1993Jan27.175539.17114@bnr.ca>
- Sender: news@bnr.ca (usenet)
- Nntp-Posting-Host: bcars6f4
- Reply-To: webster@bnr.ca
- Organization: Bell Northern Research Ltd
- References: <1993Jan26.194057.1884@unix.brighton.ac.uk>
- Date: Wed, 27 Jan 1993 17:55:39 GMT
- Lines: 45
-
- In article 1884@unix.brighton.ac.uk, ndl@unix.brighton.ac.uk (Nathan Lock) writes:
- >How can I take a variable length field
- >(e.g the gecos field in the password file)
- >and pad it out in a shell script so that it is always the same length
- >for the next field to line up.
- >(with a tab I will not always get the same column, sometimes I need 1,
- >other times 2 for a shortname) how can I determine whether I need 1 or 2
- >in a shell script?
- >
- >e.g a single tab
- >
- >Fred Bloggs next field
- >Joe Smith next field
- >Samantha Smith-jones next field
- >Sam Wheeler next field
- >
- >what I want to achieve:-
- >
- >Fred Bloggs next field
- >Joe Smith next field
- >Samantha Smith-Jones next field
- >Sam Wheeler next field
- >
- >Standard shell or awk solutions please as I do not have perl etc.
- >
- >Awaiting you reply
- >
- >Nathan Lock.
- Try awk ie
- % echo "biff stuff junk"|awk -F" " '{printf "%-30s %s\n",$1, $2}'
- biff stuff junk
-
- where
- echo "biff stuff<a tab>junk"|awk -F"<a tab>" '{printf "%-30s %s\n",$1, $2}'
- ---
- *************************************************************
- Brent Webster (CoDesign Tools & Modelling)
-
- Bell-Northern Research Ltd * Ph : (613) 763-4962
- P.O. Box 3511, Station C * Fax: (613) 763-7742 or 2626
- Dept 9R12, MS103 * InterNet/NetNorth: webster@bnr.ca
- OTTAWA,Ont,Canada K1Y 4H7 * Bitnet: webster@bnr.ca.bitnet
- *************************************************************
- #include <std.disclaimer>
-
-