Bash for loop with two variables

Hi,

I have the following folder structure:

TST500-1000
TST500-2000
TST500-3000
TST700-1000
TST700-2000
TST700-3000
TST900-1000
TST900-2000
TST900-3000

I would like to store the numbers in the first column (considering "-" as column separator) into a variable then the numbers in the 2nd column into another variable.

When I run :

for i in $(ls -1 -d TST* | awk '{print substr($0,4,3)}') ; do for j in $(ls -1 -d TST$i* | awk -F- ' {print $2}'); do echo $i $j ; done ; done

it duplicate all values:

500 1000
500 2000
500 3000
500 1000
500 2000
500 3000
500 1000
500 2000
500 3000
700 1000
700 2000
700 3000
700 1000
700 2000
700 3000
700 1000
700 2000
700 3000
900 1000
900 2000
900 3000
900 1000
900 2000
900 3000
900 1000
900 2000
900 3000

Would be possible to adjust the command to get the same number of values as folders:

500  1000
500  2000
500  3000
700  1000
700  2000
700  3000
900  1000
900  2000
900  3000

Thanks in advance,

Alex

for x in $(ls TST*);do i=${x:3:3} j=${x:7:6};echo $i $j;done
500 1000
500 2000
500 3000
700 1000
700 2000
700 3000
900 1000
900 2000
900 3000
1 Like
for i in TST*
do 
  n=${i#TST}
  echo "${n%-*}" "${n#*-}"
done
1 Like

Thank you so much, it worked like a charm.