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
296 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 35 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 30 total points
ID: 22660780
try

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

Assisted Solution

by:ahoffmann
ahoffmann earned 30 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 30 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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

696 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