-1

I'm trying to replace a string in a filename:

Original filename:

gamename games.com.zip

Target filename:

gamename.zip

I'm trying to replace the string games.com with an empty string. gamename is not a constant string it can be anything, but games.com is a constant string.

4

3 回答 3

1

我会用

mv "$filename" "${filename/ games.com/}"

这记录在“Bash”手册页中的“模式替换”下

http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion在线

于 2013-03-04T14:29:29.067 回答
1

Bash 参数扩展将有助于:

mv "$f" "${f/ games.com}"
于 2013-03-04T14:30:36.063 回答
0

尝试以下rename命令:

$ filename="gamename games.com.zip"
$ rename " games.com" "" "$filename"

由于您的 zip 文件的名称有一个空格,因此您需要确保将其括在双引号中。

于 2013-03-04T14:13:02.067 回答