Underscore in rename command (Perl and Unix shell)

匿名 (未验证) 提交于 2019-12-03 01:03:01

问题:

I'm trying to replace all _ underscore character by - hyphen character in all file names .mat inside one folder. I type different versions unsuccessfully of:

rename -f 'w/_/-' *.mat 

Can someone explain to me what is wrong?

回答1:

If you're using a Perl-based rename (as your tags suggest) then w isn't a Perl regex operation.

rename -f 's/_/-/g' *_*.mat 


回答2:

I cannot fathom whether you are using a shell rename or the Perl rename: I can't understand your command in either context.

A Perl command-line script to rename all *.mat files in the current directory looks like this

perl -e 'do { (my $f = $_) =~ tr/_/-/; rename $_, $f } for glob "@ARGV"' *.mat 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!