Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File Bash脚本循环遍历要在特定索引处删除的文件名_File_Bash_Rename - Fatal编程技术网

File Bash脚本循环遍历要在特定索引处删除的文件名

File Bash脚本循环遍历要在特定索引处删除的文件名,file,bash,rename,File,Bash,Rename,我有很多文件的名称如下: nn - xxxxxxxxxxxxxx-OOO.ext 其中,nn始终是两位数,xxxxx是可变长度的文本。(后缀-OOO在所有文件中都是静态的)。要将文件重命名为,循环中应包含哪些内容: xxxxxxxxxxxxxx.ext 因此,删除nn-(始终是前5个字符)和-oo可以通过两个子字符串操作来完成: $ name="nn - xxxx x xx xx xxxxx-OOO.ext" $ part1=${name:5} # sub

我有很多文件的名称如下:

nn - xxxxxxxxxxxxxx-OOO.ext
其中,
nn
始终是两位数,
xxxxx
是可变长度的文本。(后缀-OOO在所有文件中都是静态的)。要将文件重命名为,循环中应包含哪些内容:

xxxxxxxxxxxxxx.ext

因此,删除
nn-
(始终是前5个字符)和
-oo

可以通过两个子字符串操作来完成:

$ name="nn - xxxx x xx xx xxxxx-OOO.ext"
$ part1=${name:5}                   # substring starting at position 5
$ part2=${part1%-OOO.ext}           # remove `-OOO.ext` at the end of $part1
$ final="$part2".ext
$ echo $final
xxxx x xx xx xxxxx.ext
$ mv "$name" "$final"

echo$file\u name | sed“s/*-\s*\(.*\)-.*/\1.ext/”
将按照您在OP中的要求提供“xxxxxxx.ext”。

我在循环构造方面遇到了一些问题。请您也显示一下好吗?到目前为止,您对此有什么要求?为什么您要求循环中应该包含什么内容?我目前有“for f in*.ext;”,但我不知道如何获取文件名。