file manipulation (easy question I think - REWORDED)

Gary Weimer 253-7796 weimer at garden.ssd.kodak.com
Wed Jun 19 02:48:00 AEST 1991


In article <1991Jun18.151428.22784 at colorado.edu>,
lewis at tramp.Colorado.EDU (LEWIS WILLIAM M JR) writes:
|> In article <1991Jun18.014539.22085 at msuinfo.cl.msu.edu>
jpd at tardis.cl.msu.edu (Joe P. DeCello) writes:
|> >
|> >To rephrase my previous question:
|> >
|> . . .
|> >The best response to my previous posting was this:
|> >
|> >awk '{printf "%s ", $1' < infile > outfile
|> >
|> >I changed this to :
|> >
|> >awk '{printf "%s, ", $1' < infile > outfile
|> >
|>  your solution simply needs another line.  Also, note addition of closing
|>  brace:
|> 	awk '
|> 		{printf "%s, ", $1}
|> 		END {printf "\n"}
|> 	' < infile > outfile

Execpt you left out the part that said: "but now I need to break off
the first field of each line from the infile at the colon."

What he really wants is:

awk -F: '{if (NR==1) {printf "%s", $1} else {printf ", %s", $1}}' < in > out

NOTES:
-F:             -- tells awk to use ':' as the field separator
if (NR==1) etc. -- eliminates the trailing comma

weimer at ssd.kodak.com ( Gary Weimer )



More information about the Comp.unix.questions mailing list