user370507 user370507 - 1 year ago 169
Bash Question

Regex to batch rename files in OS X Terminal

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


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

Answer Source

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' |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download