View Single Post
  #8 (permalink)  
Old 08-08-03, 00:38
msetjadi msetjadi is offline
Registered User
 
Join Date: Jun 2003
Posts: 35
Yes it works. Thank You for all suggestion.


Quote:
Originally posted by Damian Ibbotson
I would do something like this for multiple files...

for fname in $(find . -name "*" -print)
do
sed '/word/s/word/new_word/g' ${fname} > ${fname}.new &&
mv ${fname}.new ${fname}
done


The 'find' command will output every filename that matches '*' (i.e. EVERY file) starting from the current directory ('.')

The 'for' loop will obviously cause the nested statements to occur for the list of substituted filenames.

The 'sed' command will substitute the word you require. Note: the initial occurrence of the word 'word' is not necessary but it makes the command more efficient as sed will only look to perform the substitution on lines that contain the match (as opposed to every line by default).

The use of '&&' is important because it means that the following command (i.e. 'mv') will only execute if the 'sed' command executed successfully.
Reply With Quote