标题的内容。txt看起来像这样。在数字和标题之间有一个标签(可以随意更改)。
001 title of 1 002 this is 2 003 and here goes 3 004 number four 005 hi this is five etc
文件夹的内容如下所示。没有例外。
file_001.ext file_002.ext file_003.ext file_004.ext file_005.ext etc
只需使用 read ,使用 awk cut (谢谢你,杰克)和 mv ./filenames
read
awk
cut
mv
./filenames
#!/bin/bash while IFS='' read -r line || [[ -n "$line" ]]; do NR=$(echo "$line" | cut -f 1) NAME=$(echo "$line" | cut -f 2) if [ -f "foo_${NR}.ext" ] ; then mv "foo_${NR}.ext" "$NAME" fi done < filenames