Computing.Net > Forums > Unix > change string in multiple file

change string in multiple file

Reply to Message Icon

Original Message
Name: plastic_tree
Date: March 8, 2003 at 03:54:23 Pacific
Subject: change string in multiple file
OS: RH linux 8.0
CPU/Ram: 1.8 P4/512mb
Comment:

hello, may i know how can i find and change string in multiple file...i had refer some of the post here .. but found that all is about find and change string in a file only..let say i want to change all occurences of the string 'hei' to 'hello' in only the file with extension .txt....how i can do that.....thanks in advance...


Report Offensive Message For Removal


Response Number 1
Name: David Perry
Date: March 8, 2003 at 09:00:45 Pacific
Subject: change string in multiple file
Reply: (edit)

#/bin/ksh
for file in `find . -name '*.txt' -type f -print` ; do
echo $file
sed -e 's/hei/hello/' $file > $file.tmp
mv $file.tmp $file
done


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: change string in multiple file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge