Bash – how to put each line within quotation

Using awk

awk '{ print "\""$0"\""}' inputfile

Using pure bash

while read FOO; do
   echo -e "\"$FOO\""
done < inputfile

where inputfile would be a file containing the lines without quotes.

If your file has empty lines, awk is definitely the way to go:

awk 'NF { print "\""$0"\""}' inputfile

NF tells awk to only execute the print command when the Number of Fields is more than zero (line is not empty).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)