?
Solved

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

Posted on 2008-10-07
5
Medium Priority
?
303 Views
Last Modified: 2013-12-26
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!
0
Comment
Question by:aggunia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 140 total points
ID: 22660666
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
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 120 total points
ID: 22660780
try

 cat file | sed -e 's/^/\"/' -e 's/$/\"/' > newfile
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 120 total points
ID: 22664967
# not as elegant as sed, but ...
gawk -v q='"' '{printf("%s%s%s\n",q,$0,q)}' inputfile
0
 
LVL 13

Assisted Solution

by:Rowley
Rowley earned 120 total points
ID: 22670047
One more!

 perl -pe 's/^(.*)$/\"\1\"/' /var/tmp/file > /var/tmp/file2
0
 

Author Closing Comment

by:aggunia
ID: 31503887
You guys rock!  All the solutions worked, so I split up the points.  Thanks again!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question