Issue
I tried to replace end of lines in a file with single quote + comma.
Content of test.txt file:
aaa
bbb
ccc
aaa',
bbb',
ccc',
I managed to replace the end of lines with comma like this:
sed 's#$#,#g' test.txt
but i always fail when trying to convert to single quote + comma.
I tried: sed 's#$#',#g' test.txt
but the command still awaiting input.
I tried various combination with quotes and double quotes but still fail.
I'd really appreciate your help. thanks.
Solution
Single quotes can't be nested. You have to end the single quotes, add an escaped or quoted single quote, than open a new quoted string.
sed 's/$/'\'',/'
sed 's/$/'"'"',/'
You can also switch the quotes and use double quotes for the whole expression:
sed "s/$/',/"
In fact, the substitution needs no quoting in this case, so you can just use
sed s/$/\',/
Answered By - choroba Answer Checked By - Senaida (WPSolving Volunteer)