How can I turn this:
aaa
bbb
ccc
into this:
aaa,
bbb,
ccc
using sed?
Note how all lines end a comma, except the last one.
In my real problem I also do some regex substitutions on the lines. Is there a solution that doesn’t duplicate them?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could use:
If you want to apply a different substitution on the last line, you can still use the
$address:The above will replace the end of the line with
;if it’s the last line, otherwise it will use,.$s/$/;/= at the last line, replace the end of the line with;$q= at the last line, quits/$/,/= replace the end of the line with,The last
scommand will run for each line, but not for the last line in which theqcommand at 2. tells it to quit.See: