oldjamey
6/13/2013 - 3:15 AM

increment a variable inside a for loop to rename all text files that start with a certain string.

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