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
287 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
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.

706 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now