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

查看:17
本文介绍了正则表达式在 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 管道中构造重命名命令并将它们提供给 shell.

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 "123" "1onetwothree2"/p' |
sh

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

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