且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

匹配和重新格式化输入错误的文件名

更新时间:2022-12-15 16:07:07

能否请您尝试一次.以下将仅在屏幕上显示重命名命令,您可以从中运行1条命令,如果对结果满意,则可以运行我的第二条代码.

Could you please try following once. Following will only print the rename commands on screen, you could run 1 command from it and if you are happy with results then you could run my 2nd code.

find . -type f -name "*.aiff*" -print0 | 
while IFS= read -r -d '' file
do
  echo "$file" | 
  awk '
    BEGIN{ s1="\"" }
    { val=$0; sub(/^\.\//,""); sub(/\.aiff/,"."$2"&",$1)
      print "mv " s1 val s1 OFS $1
    }'
done

或者,如果要放置条件并检查文件名是否有空格,请在awk命令中添加一个附加条件,它将跳过名称中没有空格的文件.

OR in case you want to put condition and check if file name has space or not so put an additional condition in awk command it will skip files which are not having space in their names.

find . -type f -name "*.aiff*" -print0 | 
while IFS= read -r -d '' file
do
  echo "$file" | 
  awk '
    BEGIN{ s1="\"" }
    NF==2{ val=$0; sub(/^\.\//,""); sub(/\.aiff/,"."$2"&",$1)
      print "mv " s1 val s1 OFS $1
    }'
done



请仅在成功测试以上代码后再运行以下程序.



Run following only after you have tested above code successfully please.

find . -type f -name "*.aiff*" -print0 | 
while IFS= read -r -d '' file
do
  echo "$file" | 
  awk '
    BEGIN{ s1="\"" }
    { val=$0; sub(/^\.\//,""); sub(/\.aiff/,"."$2"&",$1)
      print "mv " s1 val s1 OFS $1
    }' | sh
done