[Chester LUG] Help with a bash script

Michael Crilly e-mail at mcrilly.co.uk
Fri May 16 10:49:06 UTC 2008


Roger, i live just around the corner from the labs! Get me a job there :)

On 5/16/08, Roger Downing <r.downing at dl.ac.uk> wrote:
> 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
>
> _______________________________________________
> Chester mailing list
> Chester at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/chester
>

-- 
Sent from Google Mail for mobile | mobile.google.com

M. T. Crilly
http://www.mcrilly.co.uk/




More information about the Chester mailing list