Code: Select all
for i in *; do sed "s/Test/Validate/g" $i; doneThis
Code: Select all
for i in *; do sed "s/Test/Validate/g" $i > $i; doneModerator: General Moderators
Code: Select all
for i in *; do sed "s/Test/Validate/g" $i; doneCode: Select all
for i in *; do sed "s/Test/Validate/g" $i > $i; done2.3.2.1 Saving output
Unless you are redirecting the output of sed to another program, you will want to capture the output in a file. This is done by specifying one of the shell's I/O redirection symbols followed by the name of a file:
$ sed -f sedscr list > newlist
Do not redirect the output to the file you are editing or you will clobber it. (The ">" redirection operator truncates the file before the shell does anything else.) If you want the output file to replace the input file, you can do that as a separate step, using the mv command. But first make very sure your editing script has worked properly!
In Chapter 4, Writing sed Scripts, we will look at a shell script named runsed that automates the process of creating a temporary file and using mv to overwrite the original file.
Code: Select all
for i in *; do sed "s/Test/Validate/g" $i > temp && mv temp $i; done