Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a comma at the end of every line

Tags:

bash

sed

I need to format a mailing list, by adding a comma at the end of every line. This question has been already asked, however I don't get the expected result with the suggested answer:

sed '$!s/$/,/' file > out.txt

results in:

[email protected]
,
[email protected]
,
[email protected]
. . .

Is there anyway it can be improved ? I'd need rather need:

[email protected],
[email protected],
[email protected],
. . .

Thanks!

like image 978
Francesco Marchioni Avatar asked Feb 13 '17 10:02

Francesco Marchioni


1 Answers

Use the following approach to add comma at the end of each line:

sed 's/$/,/' file > out.txt

s/regexp/replacement/flags

like image 134
RomanPerekhrest Avatar answered Nov 04 '22 05:11

RomanPerekhrest