Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change multi lined file into one line seperated by commas 2

Status
Not open for further replies.

pneumatic

Technical User
Aug 6, 2003
11
0
0
GB
all,

using unix aix -
i'm in a rush (aren't we all!) and need to change a file with several lines...
example:
ca1245
fc6789
rd7452
dp0329

into a one line file seperated by commas(using the example above) ie:
ca1245,fc6789,rd7452,dp0329

any suggestions would be welcome. not perl please.
thankyou in advance.

 
very quick and dirty you could use something like this....

cat filename | while read LINE
do
echo "$LINE,\c" >> newfile
done

Then just edit the file to remove the last comma in the line.

Jim Hirschauer
 
jim,

many thanks for the fast response, simple is best it works a treat. :)

again, thankyou.
 
Try

sed -e :a -e '$!N;s/`n/,/;ta' filename > newfilename

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
I like the paste command for this.

paste -d, -s filename

so if
ca1245
fc6789
rd7452
dp0329

are in a file named my_items, then
paste -d, -s my_items
will produce:
ca1245,fc6789,rd7452,dp0329

It also works with standard input from the command line.
cat my_items | paste -d, -s -
also produces:
ca1245,fc6789,rd7452,dp0329
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top