Download and view my resume (PDF)

Wednesday, October 6, 2010

Add zeros to filenames in UNIX

This is a one-liner for adding zeros to filenames in UNIX. I give it here for my own future reference, lest I have to spend this long yet again to figure out where every backtick, single-quote, and semicolon should go.

for file in `find . -maxdepth 1 -type f -print`; do mv $file `basename $file|sed -r 's/([a-z])([0-9])$/\10\2/'`; done

The difficult part here is the sed replacement, which looks for a letter followed by a number, and replaces it with the letter, then a zero, then the number.

No comments:

Post a Comment