how to rename all file name which contain specific word to another word in a folder using bat or shell script
how to write a batch script or shell script to rename files in a folder
ie ..replace the name arun_XYZ to arun_ABC present in all 开发者_如何学Pythonfile names (replace xyz to abc)
and how to also replace a word XYZ present inside all files with the word ABC
Shell:
To rename files:
for fname in *_XYZ; do
newname=`echo "$fname" | sed 's/_XYZ/_ABC/g'`
echo "$fname" "$newname"
done
After testing replace echo $fname...
to mv $fname...
.
To rename tiles and replace files content:
for fname in *_XYZ; do
newname=`echo "$fname" | sed 's/_XYZ/_ABC/g'`
sed 's/XYZ/ABC/g' "$fname" >"$newname"
done
As this question has the "dos-batch" tag, I assume that Arunachalam needs a dos solution, not a bash one.
You asked two completly different questions.
For renaming filenames you could look at batch-script-to-rename-files- or how-to-change-file-extensions
For changing the file content you could read Batch Substitute
精彩评论