| |||||||||
| ||||||||||||||
Author: Engys | Topic: Reverse a file sequence | Last change: 2014-11-06 14:09:08 | ||||||||||||
I think this script speaks for itself:
#!/bin/bash if [ "$1" == "" ]; then echo echo "reverse 1.0 is a lumalab.net bash script to reverse a file sequence." echo "This script is using sed." echo "Usage as xfce custom action command: reverse.sh %n" echo echo "Shell usage: reverse.sh <name>.<ext>" echo echo "Example: reverse.sh image0122.png" echo echo " This example will reverse a file sequence in the current directory" echo " with the name image and the extension png" echo " based on the starting number 0000" echo echo "This script has the intension to be useful but comes without any warranty." echo "Feel free to modify it for your own purpose." echo else IN_NOEXT=`echo "$1" | cut -d'.' -f 1` # remove extension IN_NAME=`echo "$IN_NOEXT" | sed 's/[0-9]*//g'` #remove all digits IN_EXT=`echo "$1" | cut -d'.' -f 2-` # get selected extension # Count sequence files COUNTER=0 for FILENAME in $IN_NAME*.$IN_EXT; do let COUNTER++ done # Create temp files to prevent overwriting for FILENAME in $IN_NAME*.$IN_EXT; do mv "$FILENAME" temp_$IN_NAME$(printf %04d $COUNTER).$IN_EXT let COUNTER-- done # Replace temp with the original file name COUNTER=0 for FILENAME in temp_$IN_NAME*.$IN_EXT; do mv "$FILENAME" $IN_NAME$(printf %04d $COUNTER).$IN_EXT let COUNTER++ done fi | ||||||||||||||
![]() | ![]() |
|