| |||||||||
| ||||||||||||||
Author: Engys | Topic: Pingpong a file sequence | Last change: 2014-11-06 14:09:52 | ||||||||||||
I think this script speaks for itself:
#!/bin/bash if [ "$1" == "" ]; then echo echo "pingpong 1.0 is a lumalab.net bash script to pingpong a file sequence." echo "This script is using sed." echo "Usage as xfce custom action command: pingpong.sh %n" echo echo "Shell usage: pingpong.sh <name>.<ext>" echo echo "Example: pingpong.sh image0122.png" echo echo " This example will pingpong 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 NEW_START=$COUNTER COUNTER=0 # Create copy for FILENAME in $IN_NAME*.$IN_EXT; do cp "$FILENAME" cpy_$IN_NAME$(printf %04d $COUNTER).$IN_EXT let COUNTER++ done COUNTER=$NEW_START # Create reverse temp to prevent overwriting for FILENAME in $IN_NAME*.$IN_EXT; do mv "$FILENAME" temp_$IN_NAME$(printf %04d $COUNTER).$IN_EXT let COUNTER-- done # move copy to original file name COUNTER=0 for FILENAME in cpy_$IN_NAME*.$IN_EXT; do mv "$FILENAME" $IN_NAME$(printf %04d $COUNTER).$IN_EXT let COUNTER++ done # Replace temp with the original file name COUNTER=$NEW_START for FILENAME in temp_$IN_NAME*.$IN_EXT; do mv "$FILENAME" $IN_NAME$(printf %04d $COUNTER).$IN_EXT let COUNTER++ done fi | ||||||||||||||
![]() | ![]() |
|