Forum Moderators: bakedjake

Message Too Old, No Replies

Help with global find + replace

Help needed

         

balaga

4:01 am on Apr 29, 2004 (gmt 0)

10+ Year Member



Hi *nix gurus,

Requesting help:

How do I do a global replace of a character or set of characters with another character or set of characters in a .txt file. The file is too large and contains some 25 million lines. I basically need to replace the field separator from \t or tab to another delimiter like '¦'

Any help is greatly appreciated.

Thanks

Balaga

giles

9:45 am on Apr 29, 2004 (gmt 0)

10+ Year Member



So you want to translate one character into another? Have a look at tr which does just that.

tr "\t" "¦" < oldfile > newfile

SeanW

12:57 pm on Apr 29, 2004 (gmt 0)

10+ Year Member



giles' suggestion of tr is the easiest way... If you have multiple files or need more complex stuff, a perl one liner can do it, too

perl -p -i -e 's/\t/¦/g' *.txt

will substitute all tabs for ¦ in all files named .txt (it's called "edit in place")

Sean

balaga

3:22 pm on Apr 29, 2004 (gmt 0)

10+ Year Member



Thanks a lot Sean and Giles. Cool!

Balaga