Underscore in rename command (Perl and Unix shell)

丶灬走出姿态 提交于 2019-12-11 00:53:51

问题


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


来源:https://stackoverflow.com/questions/10055412/underscore-in-rename-command-perl-and-unix-shell

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