[Gllug] Shell script to sort filenames
t.clarke
tim at seacon.co.uk
Fri Dec 27 10:12:46 UTC 2002
MANJUSH wrote concerning a shell script to sort file-names within several
directories into alphabetical order.
I am not totally sure if the following does what is required, but you can
try it. The script is crude, but it appears to work
Invocation is simply:
script-name -f directory1 directory2 .......
or
script-name -r directory1 directory2 .......
Tim
if [ $# -lt 2 ]
then
echo "insufficient parameters; must be -f[r] and at least one directory"
exit
fi
A=$#
ORDER=$1
if [ $ORDER != "-r" -a $ORDER != "-f" ]
then
echo "sort order not specified (-f or -r)"
exit
fi
cat /dev/null > /tmp/sort
A=`expr $A - 1`
while [ $A -gt 0 ]
do
A=`expr $A - 1`
shift 1
echo "$1"
ls "$1" >> /tmp/tosort
done
sort $ORDER /tmp/tosort > /tmp/sorted
rm /tmp/tosort
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list