Results 1 to 3 of 3
Hello,
I have just changed a setting and I need to go through about 30 files within a directory and find all instances of a word, and change it to ...
- 07-18-2008 #1Just Joined!
- Join Date
- May 2007
- Posts
- 24
Can I use grep to find & replace text?
Hello,
I have just changed a setting and I need to go through about 30 files within a directory and find all instances of a word, and change it to another word.
My intial though was GREP was the tool to use, however, I looked in the man pages and I can't find a "find & replace" option within it.
Is there a way that I can use grep to look into every file within the directory and change the word?
any help is greatly appreciated.
- 07-18-2008 #2
Sed might be what you need
That will replace all occurences of word1 with word2 inside yourfile.txt.Code:sed 's/word1/word2/' yourfile.txt
Last edited by smolloy; 07-18-2008 at 11:20 PM. Reason: typo in command
Registered Linux user #388328 || Registered LFS user #15880
AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
Need instant help? Try us on IRC -- #linuxforums on freenode
- 07-18-2008 #3
and dont forget the -i and g options for sed.
see the man page
Code:man sed
Linux and me it's a love story


Reply With Quote