Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!cis.ohio-state.edu!ucbvax!bloom-beacon!eru!hagbard!sunic!dkuug!ruc.dk!jba From: jba@gorm.ruc.dk (Jan B. Andersen) Newsgroups: comp.unix.questions Subject: Re: file manipulation (easy question I think - REWORDED) Keywords: awk sed Message-ID: <1991Jun18.195126.9916@gorm.ruc.dk> Date: 18 Jun 91 19:51:26 GMT References: <1991Jun18.014539.22085@msuinfo.cl.msu.edu> Organization: Roskilde University, Denmark Lines: 33 jpd@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@cad.msu.edu >Michigan State University phone: (517) 353-3027 >Specialized Computing Support Services -- /| / Jan B. Andersen /^^^\ .----------------. / | / RUC, Hus 19,1 jba@dat.ruc.dk { o_o } | SIMULA does it | /--|/ Postbox 260 DG-passer@ruc.dk \ o / --> | with CLASS | `--' ' DK-4000 Roskilde Postmaster@ruc.dk --mm---mm-- `----------------'