file manipulation (easy question I think - REWORDED)

Jan B. Andersen jba at gorm.ruc.dk
Wed Jun 19 05:51:26 AEST 1991


jpd at tardis.cl.msu.edu (Joe P. DeCello) writes:


>To rephrase my previous question:

>Suppose I have a file containing several lines of text.
>Each line is an entry for a database (or whatever) and
>let's say each line contains 8 fields.  The fields are
>separated by colons.

Very similar to /etc/passwd then.

>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?

>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>Joseph P. DeCello III                e-mail:  jpd at cad.msu.edu
>Michigan State University             phone:  (517) 353-3027
>Specialized Computing Support Services
-- 
      /|  / Jan B. Andersen                        /^^^\     .----------------.
     / | /  RUC, Hus 19,1     jba at dat.ruc.dk      { o_o }    | SIMULA does it |
    /--|/   Postbox 260       DG-passer at ruc.dk     \ o / --> | with CLASS     |
`--'   '    DK-4000 Roskilde  Postmaster at ruc.dk --mm---mm--  `----------------'



More information about the Comp.unix.questions mailing list