且构网

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

使用perl表达式批量重命名文件

更新时间:2023-11-22 23:33:22

我认为您不需要使用 mmv ,一个简单的 mv 即可.另外,无需指定 IFS ,默认设置将对您有效:

I don't think that you need to be using mmv, a simple mv will do. Also, there's no need to specify the IFS, the default will work for you:

while read -r src dest; do mv "$src" "$dest"; done < names.txt

我将变量名加双引号,因为通常认为这是一种好习惯,但是在这种情况下,任何一个文件名中的空格都会导致 read 不能按预期工作.

I have double quoted the variable names as it is generally considered good practice but in this case, a space in either of the filenames will result in read not working as you expect.

您可以在循环内的 mv 之前放置 echo ,以确保将执行正确的命令.

You can put an echo before the mv inside the loop to ensure that the correct command will be executed.

请注意,在文件 names.txt 中,已经包含了 .fasta.gz 后缀,因此您也不应将其添加到循环中.也许那是你的问题?

Note that in your file names.txt, the .fasta.gz suffix is already included, so you shouldn't be adding it inside the loop aswell. Perhaps that was your problem?