Code snippet
I had a bunch of files with duplicate extensions (filename.jpg.jpg) and wanted to trim it to one .jpg so I did this:
ls *.jpg.jpg | awk '{print("mv "$1" "$1)}' | sed 's/.jpg.jpg/.jpg/2'
which just printed the results to stdout. I fiddled with the command until it output what I wanted, then I appended | /bin/sh to get this:
ls *.jpg.jpg | awk '{print("mv "$1" "$1)}' | sed 's/.jpg.jpg/.jpg/2'|/bin/sh
which renamed the files appropriately. Cool.
Something similar can be accomplished thusly:
find . -iname "*pattern1*" -exec echo "mv '{}' '{}'" \; | sed 's/pattern2/pattern3/2' | /bin/sh
where: pattern1 is the mask that select which files to process; pattern2 is the string to be modified; and pattern3 is the substitution for pattern2 (leave empty for deletion)