Page 1 of 1

Replacing text in multiple files! Guru stuff

Posted: 18 Nov 2011, 00:10
by viking60
Here is a tip with high Guru factor that will make you the center of attention on every party:
You have just broke up with Cyntia and you rather fancy Jane now.
Your Documents directory is full of those romantic love letters that worked so well with Cyntia.
So in Cyntia1.txt you put:
Cyntia I love you

In Cyntia2.txt
You are the best Cyntia

Etc etc. So to avoid doing all that hard work again you can do the following in your Documents directory:

Code: Select all

perl -i -pe 's/Cyntia/Jane/;' Cyntia*

And voila in all files starting with Cyntia "she" will be replaced with Jane.
You can also replace Cyntia in the text with a sentence like this:

Code: Select all

perl -i -pe 's/Cyntia/Jane I love you/;' Cyntia*


What a great party trick! ... If that doesn't get you the girl nothing will!

LibreOffice is somewhat unromantic though and registers that the odt file has been manipulated. You get the offer to "fix" it and thus you are stuck with Cyntia.

Works great on text files though.

Re: Replacing text in multiple files! Guru stuff

Posted: 18 Nov 2011, 06:52
by dubigrasu
Poor Cyntia :|

Re: Replacing text in multiple files! Guru stuff

Posted: 18 Nov 2011, 11:49
by viking60
:-D
Yes ..but you see he had no choice:
Jane is an Eduard Khil fan. +1
Image