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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append , at the end of each line except the last line

Status
Not open for further replies.

infdeveloper

Programmer
Feb 23, 2005
4
US
Hello,

Could you please help me answer the question
I have a file like
x
y
z

I want it to append , at the end of each file except the last file
x,
y,
z

I am getting , at the end of each line with sed 's/$/,/' but I dont want it at end of the last line

Thanks

Could you please help me get this
 
Hi,

Use this sed sequence will do the job

sed -e '1,$ s/$/,/' -e '$ s/,$//' /path/to/your_file > new_file

the 1st -e puts a comma after all the lines
the 2nd -e supresses the comma putted on the the last line by the 1st -e

Ali
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top