Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append a character at the end of each line in unix

Tags:

unix

append

I have a large data file and I need to append comma at the end of each line.How can I accomplish this? Thank you.Here is my sample data file as below.

1000050G8611
1000200G8611
1000250G8611
1000350G8611
1000375G8611
1000376G9403
1000475G8611
1000500G8611
1000550G8611
1000600G8611
1000610G8611
1000611G0807
1000612G0804
1000614G0802
1000617G8611
1000618G0710
1000619G8611
1000621G8611
1000624G0606
like image 679
Teja Avatar asked Feb 06 '13 18:02

Teja


2 Answers

 awk '{print $0 "," }' file > outFile

 sed 's/$/,/' file > outFile

 sed -i 's/$/,/' file

If your sed supports the -i option.

IHTH

like image 89
shellter Avatar answered Sep 29 '22 07:09

shellter


This should do the trick awk '{ print $0 "," }' < inputfile

like image 45
TopGunCoder Avatar answered Sep 29 '22 06:09

TopGunCoder