[Chester LUG] Help with a bash script

Roger Downing r.downing at dl.ac.uk
Fri May 16 10:20:59 UTC 2008


On Friday 16 May 2008 11:04:21 Stuart Burns wrote:
> Hi Michael
>
> That is a good idea. However it needs to be chronologically ordered as the
> file numbers are sequential and need to dealt with by the other program in
> order. Really good idea though.
>
> Stu

To do a loop in bash that counts up an increment you can do something like 
this:

<<< CUT >>>
COUNTER=1
FILENAME=myfile.txt
printf -v INCREMENT "%04d" $COUNTER

while [ -r $FILENAME.$INCREMENT ]
do
        let COUNTER=$COUNTER+1
        printf -v INCREMENT "%04d" $COUNTER
done

# At this point we should have the first number that does not yet exist

echo "Output is $COUNTER"
<<< CUT >>>

Hope this helps!

Cheers,

-- 
Roger Downing
eScience systems administrator
STFC
Daresbury Laboratories
Keckwick Lane
Warrington
WA4 4AD

Tel: 01925 603937
Mbl: 07880 736154




More information about the Chester mailing list