开发者

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.

  1. For renaming filenames you could look at batch-script-to-rename-files- or how-to-change-file-extensions

  2. For changing the file content you could read Batch Substitute

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜