Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2004
    Posts
    31

    Unanswered: 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.

  2. #2
    Join Date
    Oct 2001
    Posts
    46
    This would be better....

    sed 's/^/"/;s/$/"/' yourFile > newFile

  3. #3
    Join Date
    Oct 2001
    Posts
    46
    And if you're in an experimental mood, you could compare timings with...

    sed 's/\(^.*$\)/"\1"/' yourFile > newFile

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    ...and with
    Code:
    awk '{print "\"" $0 "\""}' yourFile > newFile

  5. #5
    Join Date
    Oct 2004
    Posts
    31
    Hey thanx for all the suggestions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •