正则表达式来一批OS X终端重命名文件 [英] Regex to batch rename files in OS X Terminal

查看:188
本文介绍了正则表达式来一批OS X终端重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的方式来批量后,用正则表达式即重命名文件。

I'm after a way to batch rename files with a regex i.e.

s/123/onetwothree/g

我记得我可以用awk和正则表达式的sed,但不可能在一起弄清楚如何管他们所需的输出。

I recall i can use awk and sed with a regex but couldnt figure out how to pipe them together for the desired output.

推荐答案

要进行重命名操作的有效方式是构建重命名命令在一个sed管道,并将其送入外壳。

An efficient way to perform the rename operation is to construct the rename commands in a sed pipeline and feed them into the shell.

ls |
sed -n 's/\(.*\)\(123\)\(.*\)/mv "\1\2\3" "\1onetwothree\2"/p' |
sh

这篇关于正则表达式来一批OS X终端重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆