1836135 Members
3141 Online
110095 Solutions
New Discussion

sequencing script

 
SOLVED
Go to solution
Vin_5
Occasional Advisor

sequencing script

Hi all,

I have the following script for sequencing files:

typeset -Z2 N
for F in $FILE_LIST
do
(( N=N+1 ))
mv ${F} ${N}${F}
done

I need to limit N to between 00 & 49. What's the most efficient way of doing this, or will I need to check each iteration and reset N to 00 once it hits 49?

Many thanks,

Vin.
5 REPLIES 5
Jdamian
Respected Contributor
Solution

Re: sequencing script

you need use modulus function.

you must use:

(( N=(N+1)%50 ))
David_246
Trusted Contributor

Re: sequencing script

typeset -Z2 N
for F in $FILE_LIST
do
(( N=N+1 ))
>>
if [ "N" -gt 49]
then
N=0
fi
<<
mv ${F} ${N}${F}
done

or in perl :

$n=0;
opendir(DIR, /my/dir);
@files = grep { /^\./ && !/^\.\.?$/ } readdir(DIR);
closedir(DIR);

foreach (@files) {
mv $_ ${n}$_;
$n = 0 if ( $n > 48 );
}

Regs David
@yourservice
David_246
Trusted Contributor

Re: sequencing script

typeset -Z2 N
for F in $FILE_LIST
do
(( N=N+1 ))
>>
if [ "N" -gt 49]
then
N=0
fi
<<
mv ${F} ${N}${F}
done

or in perl :

$n=0;
opendir(DIR, /my/dir);
@files = grep { /^\./ && !/^\.\.?$/ } readdir(DIR);
closedir(DIR);

foreach (@files) {
$n++;
mv $_ ${n}$_;
$n = 0 if ( $n > 48 );
}

Regs David
@yourservice
Michael Steele_2
Honored Contributor

Re: sequencing script

Define your list to be an array then use nested loops to automatically restart to zero.

LIST=( 00, 01, 02.... 49 }



typeset -Z2 N
for F in $FILE_LIST
do

for x in $LIST
do

mv ${F} ${N}${F}

done
(( N=N+1 ))
done
Support Fatherhood - Stop Family Law
Vin_5
Occasional Advisor

Re: sequencing script

Sorted now!

Many thanks for all the replies.