I wanted to change "/artscrafts/" to "/blog/" in all popup image files (these are not stored in the MT database so search-and-replace inside the Movable Type 4.01 administrative interface doesn't work for those files). The file for each popup image is stored in the same directory as the popup image.
The following worked for me, but there is no guarantee that it will work for you. I am not responsible for any problems you may encounter. Backup all files first.
To change a string of characters to a different string of characters in multiple files:
- At a Unix prompt, cd to directory where the files to be modified are located
- Type on one line:
for f in *php; do sed 's/string1/string2/g' $f > $f.new && mv $f.new $f; done
Line 2 means: For every file ending with php, replace string1 with string2 and save the result into a new file, then move the new file over the original file.
For each slash in the string, I needed to use \ in front of it, as follows:
for f in *php; do sed 's/\/artscrafts\//\/blog\//g' $f > $f.new && mv $f.new $f; done
Multiple lines can also be used at a Unix prompt as follows:
for f in *php
do
sed 's/string1/string2/g' $f > $f.new &&
mv $f.new $f
done
Based on information in a thread at dBforums. Note: That code uses the Unix find command to locate files which could be in subdirectories. Back up all files and learn about the find command before using.
for fname in $(find . -name "*" -print)
do
sed '/word/s/word/new_word/g' ${fname} > ${fname}.new &&
mv ${fname}.new ${fname}
done










Very useful!
Thank you very much,.
Herman.
I am trying to compile a script to edit the /etc/login.defs
The file read:
PASS_MAX_DAYS 999999
PASS_MIN_DAYS 0
PASS_MAX_LEN 7
I would like to be able to change it to read
PASS_MAX_DAYS 60
PASS_MIN_DAYS 1
PASS_MAX_LEN 14
I tried the sed command:
sed 's/PASS_MAX_DAYS */PASS_MAX_DAYS 60/g' /etc/login.defs
the result is this
PASS_MAX_DAYS 60 99999999
How do have it replace the entire line with my input?
I have to admit I am a novice and there may be a simple answer so bear
with me
thanks
Hi, Ed - I don't use sed often and am very rusty. You might find these links helpful:
http://www.grymoire.com/Unix/Sed.html
http://student.northpark.edu/pemente/sed/sed1line.txt
Hi Ed,
you have to 'ESCAPE' the special character - an empty space in this case.
You should do it like this:
sed 's/PASS_MAX_DAYS\ 999999/PASS_MAX_DAYS\ 60/g' /etc/login.defs
If you want to replace everything after the 'PASS_MAX_DAYS' string:
sed 's/PASS_MAX_DAYS.*/PASS_MAX_DAYS\ 60/g' /etc/login.defs
Hope this helps.
When working with paths you can use:
sed 's|/usr/bin|/home/usr/|g'