Coding Knowledge Center
Sed
Subsititution (script) |
#!/bin/bash
for file in $(find . -type f -name '*\.php')
do
sed 's/[from]/[to]/g' $file > $file.tmp
mv $file.tmp $file
done
Gets a listing of all files in the current working directory with .php as an extension.
Then it loops through each file, substituting the text specified in [from] to the text specified in [to].
The output is written to a temporary file which then overwrites the original file.
Subsititution (simple) |
sed 's/[from]/[to]/' [filename]
Substitutes the text specified in [from] to the text specified in [to] then sends it to standard output.
Subsititution (to file) |
sed 's/\([0-9]\{5\}\)=11/\1=05/g' [filename-in] >> [filename-out]
Substitutes all lines in [filename-in] with pattern of "5 digits=11" to "5 digits=05", storing the 5 digits and then reusing it in the substitution, then sends each line to [filename-out].