Monday, June 25, 2012

How to modify multiple filenames at once from the command line


How to modify filenames for a bunch of files via the command line

Requirements : cygwin (or Linux) and awk

Say for instance you have image files of this format

IMG_1000 (Custom).JPG

And you want to take out "(Custom)"


The following command can be used to solve this problem and be adapted for other scenarios:

ls | awk '{ split($0,a," "); b="mv \"" $0 "\" "  a[1]a[3]; system( b); }'

Piping the output from ls to awk, this splits the file name by spaces, and renames the file to IMG_1000.JPG.

a[1] = IMG_1000
a[2] = (Custom)
a[3] = .JPG



No comments:

Post a Comment