Skip to content

Instantly share code, notes, and snippets.

@phx
Created June 13, 2013 03:15
Show Gist options
  • Save phx/5770979 to your computer and use it in GitHub Desktop.
Save phx/5770979 to your computer and use it in GitHub Desktop.
increment a variable inside a for loop to rename all text files that start with a certain string.
#!/bin/bash
for files in old*.txt
do
((i++))
mv $files $(echo $files | sed -E 's/[0-9]+\.txt//')OLDOLD$i.txt
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment