file manipulation (easy question I think - REWORDED)

der Mouse mouse at thunder.mcrcim.mcgill.edu
Thu Jun 20 19:29:27 AEST 1991


In article <1991Jun18.195126.9916 at gorm.ruc.dk>, jba at gorm.ruc.dk (Jan B. Andersen) writes:
> jpd at tardis.cl.msu.edu (Joe P. DeCello) writes:
>> I would like to be able to output the first field of each line into
>> a new file.  I would like these fields to be on one line in the new
>> file and separated by commas.

> Easy. We'll use cut(1) to select field no. 1 using ':' as the
> delimiter, and will then use tr(1) to translate the newlines into
> commas:

>   $ cat OLDFILE | cut -d: -f1 | tr "\012" "," > NEWFILE

> The only problem is what to do with the last comma?

Not the only problem; you're also missing the trailing newline.

< OLDFILE awk -F: 'BEGIN { pref = ""; } { printf("%s%s",pref,$1); pref = ","; } END { printf("\n"); }' > NEWFILE

					der Mouse

			old: mcgill-vision!mouse
			new: mouse at larry.mcrcim.mcgill.edu



More information about the Comp.unix.questions mailing list