M BUZZ CRAZE NEWS
// general

Can I non-manually add a comma to the end of hundreds of lines of text?

By Emma Johnson

I have hundreds of rows of text like so:

aaabbbccc
dddeeefff
ggghhhiii

They do not have a space at the end.

I want to add a comma to the end of each line. Is there a way to non-manually achieve this?

0

2 Answers

With sed

$ sed 's/$/,/' file
aaabbbccc,
dddeeefff,
ggghhhiii,

It should be possible to do the same with gedit's search and replace by checking Regular expression box; if that doesn't work then replace \n by ,\n and modify the last line if necessary.


Some other command-line ways:

awk -vORS=',\n' 1 file

or similarly

perl -lpe '$\=",\n"' file

If your rows of text are in the file ttt and you want commas in blank lines,

sed 's/$/,/' ttt

else if you want blank lines to remain blank

sed 's/.$/&,/' ttt

Redirect the output to a file output like so

sed 's/.$/&,/' ttt > output

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy