1

I have two loops but I don't know if its possible put all together:

First, I merge two diferents ids from the same sample:

samples="sample01 sample02 sample03"
for s in ${samples}
do
    cat ${s}_id1.txt ${s}_id2.txt > ${s}_id12.txt
done

With this I count how many data are unique in my sample.txt with a range from 19 - 41 and put the result in count.txt

for ((t=17, i=1; t<43; t=t+2, i++))
do 
    echo "[$i] Iteration - t = $t"`
    unique.py -o count.txt -t $t sample.txt
done

What I want is put the diferents values for $t for each ${s} sample_id12.txt element. Something like this:

samples="sample01 sample02 sample03"
for s in ${samples} ¿counter?
do
    cat ${s}_id1.txt ${s}_id2.txt > ${s}_id12.txt
    unique.py -o count.txt -t $t ${s}_id12.txt
    rm ${s}_id12.txt
done
  • 1
    Is there a reason you can't use a nested loop? Aside from that, I don't understand what the $i is for - it doesn't seem referenced at all. – Dani_l Jan 15 '16 at 6:09
  • Sorry, is for my log echo "[$i] Iteration - t = $t" – zorbax Jan 15 '16 at 6:14
  • Not really knowing the nested loops. I've learned something new. Thank you – zorbax Jan 15 '16 at 6:30
2

A nested loop example

samples="sample01 sample02 sample03"
for s in ${samples}
do
    cat ${s}_id1.txt ${s}_id2.txt > ${s}_id12.txt
    for ((t=17, i=1; t<43; t=t+2, i++))
    do 
        echo "[$i] Iteration - t = $t"
        unique.py -o count.txt -t $t ${s}_id12.txt
    done
done
1
for ((t=17; t<43; t=t+2))
do 
    samples="sample01 sample02 sample03"
    for s in ${samples}
    do
        cat ${s}_id1.txt ${s}_id2.txt > ${s}_id12.txt
        unique.py -o count.txt -t $t ${s}_id12.txt
    done
done

With this I get each file with ,t between 17-41 in count.txt file (unique.py overwrites the results with the t corresponding to each value in each samplefile.

sample01_id12.txt 
sample02_id12.txt
sample03_id12.txt
  • I believe that you should up-vote and probably accept @Dani_I solution as he helped you get the solution. – user79743 Jan 15 '16 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.