LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Simple find&replace across 100 files (https://www.linuxquestions.org/questions/linux-newbie-8/simple-find-and-replace-across-100-files-610866/)

saphil 01-03-2008 11:38 AM

Simple find&replace across 100 files
 
I am not a newbie, exactly, as I have been blowing up Linux boxes for about 5 years. I have even been running alpha-testing of ubuntu flights for a while, but I have never had to do any real awk or sed programming and so I find myself in an odd place. I am finding various posts about how to escape control characters but this just distracts me from exactly how (starting from exactly where in a path one would do this) one would do a simple find and replace of a string bill@noranthon.com with wolf@noranthon2.com. If it takes too awfully long to figure it out, I will just wait until my Intro to Linux Programming book arrives, and open each file in kAte and do all the replacements serially.

Thanks for your help.
(No I don't know how to do it in DOS either) lol

-saphil

matthewg42 01-03-2008 12:03 PM

Escaping a character just means that you are explicitly saying "don't treat this character as a special character". sed and various other tools use regular expressions, which define various special characters.

The only special character in the email address which you want to replace is the period character (.), which means "any character". To escape it, and treat it like a literal period character, just prefix it with a backslash. You only need to escape the period character in the search pattern - not the replacement string.

Here's how you would do the replacement in all files whose name ends in ".txt" in the present working directory:
Code:

sed -i 's/bill@noranthon\.com/wolf@noranthon2.com/g' *.txt
warning: this command will modify files in which the pattern is found.

DotHQ 01-03-2008 12:21 PM

opps, never mind.


All times are GMT -5. The time now is 04:34 AM.