[Techtalk] Re: real life kewl text-processing and regexps samples
rb at tertius.net.au
Sat Jan 10 17:19:11 EST 2004
Carla Schroder wrote:
> I want anything and everything, what I like best are useful snippets that
> actually do something. For example, Telsa posted this on one of the lists:
> man foo | col -b > filename
> This strips the control characters and creates a nice editable file. How cool
> is that?
My favourite is using perl for in-place editing of zillions of files.
eg when I changed my login from gossamer to rb I had to change
the string in a lot of files, hence:
perl -pie 's/\bgossamer\b/rb/g' *.txt
will swap every instance of the word (as a word) "gossamer" to "rb" in
*.txt in the current directory, making a backup of each file as
originalfilename.bak (that's the -i) just in case of grevious error (and
you do know how to use mmv to put the bak files back just in case,
>From memory, it'd be
mmv '*.txt' '#1'
for anybody who's interested. mmv rocks.
: Usual state: (e) None of the above.
: rb at tertius.net.au http://tertius.net.au/~rb/
: Think of the most powerful thing you can (I mean like a black
: hole or a supernova, not a Chevy). Double it. Add sharp things.
: Remove all goodness. Wrap it in a cute, cuddly bunny costume.
: -- John Chaffey (on what a DevilBunny is)
More information about the Techtalk