How do I insert a double-quote before and after a line in a text file on a Unix box?

On a Unix server, I have a flat file that has multiple lines.  Many of the lines have spaces in them.  I'd like to be able to insert a double-quote before and after each line in the file.  How can I do this via shell commands?  Thanks!
agguniaLead ConsultantAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
sunnycoderConnect With a Mentor Commented:
Hello aggunia,

>I'd like to be able to insert a double-quote before and after each line in the file.  
sed 's/\(.*\)/"\1"//'  inputfile

Regards,

sunnycoder
0
 
omarfaridConnect With a Mentor Commented:
try

 cat file | sed -e 's/^/\"/' -e 's/$/\"/' > newfile
0
 
ahoffmannConnect With a Mentor Commented:
# not as elegant as sed, but ...
gawk -v q='"' '{printf("%s%s%s\n",q,$0,q)}' inputfile
0
 
RowleyConnect With a Mentor Commented:
One more!

 perl -pe 's/^(.*)$/\"\1\"/' /var/tmp/file > /var/tmp/file2
0
 
agguniaLead ConsultantAuthor Commented:
You guys rock!  All the solutions worked, so I split up the points.  Thanks again!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.