If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Most efficient way to insert a leading and trailing double-quote

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-16-05, 02:13
bluwulf bluwulf is offline
Registered User
 
Join Date: Oct 2004
Posts: 31
Most efficient way to insert a leading and trailing double-quote

What would be the easiest and most efficiet way to put a leading and trailing double-quote on every line in a file (that has 10 MIL lines)


I kno this works:

Code:
sed "s/^/\"/" my_10MIL_LINE_file.txt | sed "s/$/\"/" > my_10MIL_LINE_file.txt.tmp

But is there a better way of doing this ? I need to do this for several 10 MIL lines file each nite.
Reply With Quote
  #2 (permalink)  
Old 10-19-05, 13:02
test test is offline
Registered User
 
Join Date: Oct 2001
Posts: 46
This would be better....

sed 's/^/"/;s/$/"/' yourFile > newFile
Reply With Quote
  #3 (permalink)  
Old 10-19-05, 13:03
test test is offline
Registered User
 
Join Date: Oct 2001
Posts: 46
And if you're in an experimental mood, you could compare timings with...

sed 's/\(^.*$\)/"\1"/' yourFile > newFile
Reply With Quote
  #4 (permalink)  
Old 10-19-05, 15:55
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,454
...and with
Code:
awk '{print "\"" $0 "\""}' yourFile > newFile
Reply With Quote
  #5 (permalink)  
Old 10-19-05, 20:28
bluwulf bluwulf is offline
Registered User
 
Join Date: Oct 2004
Posts: 31
Hey thanx for all the suggestions.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On