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?
02 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 fileor similarly
perl -lpe '$\=",\n"' file If your rows of text are in the file ttt and you want commas in blank lines,
sed 's/$/,/' tttelse if you want blank lines to remain blank
sed 's/.$/&,/' tttRedirect the output to a file output like so
sed 's/.$/&,/' ttt > output More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"