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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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…
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…

791 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