2017-05-31 26 views
0

不工作我使用Windows 7 在我的目录下的cygwin有像重命名正则表达式中的cygwin

fort.100 fort.101 ... fort.1xx

文件,我想给他们所有的扩展_v1。 当我尝试使用rename通过

rename 's/$/_v1/' fort.*

及时退出,没有错误,以实现它和没有任何反应。 我又试图

rename -e 's/$/_v1/' fort.*,错误弹出,
rename: unknown option -- e

我也用不同的分隔符@,而不是/没有运气尝试。

现在,我认为这是由于表达式中的字符_(我是regex的新手),我试图通过\_逃脱它,但没有运气。再次尝试没有_,例如,

rename 's/$/v11/' fort.* - 什么也没有发生。

虽然我通过

for file in fort.*; do mv $file $file\_v1; done实现我的目标,我不知道为什么rename不起作用。

我在这里做错了什么?是因为我在cygwin吗?

+0

尝试'重命名-E's/$/_ v1 /'堡垒。*' –

+0

@WiktorStribiżew不起作用,退出时出现错误'rename:unknown option -E'。 –

+0

如果你做一个'man rename',它是一个busybox light版本的二进制文件还是原始的binay? – Esteban

回答

0

我已经找到了解决办法。 我将util-linux rename更换为perl rename单独的包装。 这是@subogeroGitHub提供的。
所有常用的rename表达式都在起作用。

0

rename的手册与您的期望不符。 我看不到正则表达式的能力。

SYNOPSIS 
     rename [options] expression replacement file... 

DESCRIPTION 
     rename will rename the specified files by replacing the first occur‐ 
     rence of expression in their name by replacement. 

OPTIONS 
     -v, --verbose 
       Give visual feedback which files where renamed, if any. 

     -V, --version 
       Display version information and exit. 

     -s, --symlink 
       Peform rename on symlink target 

     -h, --help 
       Display help text and exit. 

EXAMPLES 
     Given the files foo1, ..., foo9, foo10, ..., foo278, the commands 

       rename foo foo0 foo? 
       rename foo foo0 foo?? 

     will turn them into foo001, ..., foo009, foo010, ..., foo278. And 

       rename .htm .html *.htm 

     will fix the extension of your html files. 

为要达到简单的方法是什么:

for i in fort*; do mv ${i} ${i}_v1 ; done 
+0

你所描述的全部都是我提出的问题。我想知道为什么以及如何使它工作。而且,我在问题中提供了您提到的同一个脚本。 –

+0

“为什么”是重命名手册所说的。该功能在cygwin中提供的版本中不存在。 – matzeri