Francesco Marchioni
Francesco Marchioni

Reputation: 4328

Add a comma at the end of every line

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!

Upvotes: 7

Views: 12408

Answers (1)

RomanPerekhrest
RomanPerekhrest

Reputation: 92854

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

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

s/regexp/replacement/flags

Upvotes: 10

Related Questions