Confusing problem of the text file - help required!

Message Bookmarked
Bookmark Removed
I have a text file with some text in it. The file is 6500 lines long. I need to insert a " symbol at the start and end of every line. There is no common link between the lines, so a simple search + replace won't do it. Anyone got any ideas?

Johnny B Was Quizzical (Johnney B), Wednesday, 5 April 2006 12:21 (twenty years ago)

Can you number or bullet the lines?

Miss Misery xox (MissMiseryTX), Wednesday, 5 April 2006 12:24 (twenty years ago)

You can do a search and replace for formatting in Word. Advanced Search and Replace includes things like line breaks.

Unless you're saying there aren't any line breaks?

Treacle in a Flaming Wheelbarrow (kate), Wednesday, 5 April 2006 12:26 (twenty years ago)

On a Unix-type system:

sed -e 's/^(.*)$/\"\1\"/'

(I *think* that's right - I'm not sure if the " characters need a \ before them)

Forest Pines (ForestPines), Wednesday, 5 April 2006 12:26 (twenty years ago)

HOW DO I SHOT VIM

Ichigo (ex machina), Wednesday, 5 April 2006 12:27 (twenty years ago)

Import it into Excel, column "B"

The rest you can guess.

mark grout (mark grout), Wednesday, 5 April 2006 12:29 (twenty years ago)

Ah, cunning.

Forest Pines (ForestPines), Wednesday, 5 April 2006 12:35 (twenty years ago)

FP's doesn't need the ^ or $ (it's the whole line, doesn't need anchoring) and the "s don't need to be quoted

sed -e 's/\(.*\)/"\1"/' infile > outfile

even shorter (by one character!) is doing it in two stages

sed -e 's/^/"/;s/$/"/' infile > outfile

koogs (koogs), Wednesday, 5 April 2006 12:38 (twenty years ago)

Ta :-)

Forest Pines (ForestPines), Wednesday, 5 April 2006 12:42 (twenty years ago)

Actually, in that last one, shouldn't the ; be a |

Forest Pines (ForestPines), Wednesday, 5 April 2006 12:43 (twenty years ago)

Hi all, I got it fixed by putting it all into Access and exporting the data as a delimited text file. Thank you for all your answers tho. There are page breaks, so that solution would have worked, but the lines are quite long - and doesn't excel chop lines that are too long?

Anyway, all done. Thanks guys!

Johnny B Was Quizzical (Johnney B), Wednesday, 5 April 2006 13:02 (twenty years ago)

what a faff. there must be a PC text editor like textwrangler/bbedit. search \r replace "\r" do the start and end yrself done.

Britain's Obtusest Shepherd (Alan), Wednesday, 5 April 2006 13:07 (twenty years ago)

There's Emacs.

Forest Pines (ForestPines), Wednesday, 5 April 2006 13:14 (twenty years ago)

seemed to work with a ; (a lucky first guess). i'd've done it (in fact i did something very similar this morning, every morning) in vim using :%s/^/" and :%s/$/"

(actually, you don't even need the -e in that sed line)

koogs (koogs), Wednesday, 5 April 2006 13:15 (twenty years ago)


You must be logged in to post. Please either login here, or if you are not registered, you may register here.