How to add double quotes to a line with SED or AWK?



I have the following list of words:


I need to have it double quoted like this:


I have tried sed 's/.*/\"&\"/g' and got:


Which has only one double quote and is missing the closing double quote.

I’ve also tried awk {print "\""$1"\""} with exactly the same result. I need help.


Your input file has carriage returns at the end of the lines. You need to use dos2unix on the file to remove them. Or you can do this:

sed 's/\(.*\)\r/"\1"/g'

which will remove the carriage return and add the quotes.

Answered By – Dennis Williamson

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More