0

I have two sets of files in two separate directories organized as such:

#first directory
/direc1/files

file0.num1.tar.gz
file0.num2.tar.gz
file0.num3.tar.gz
file0.num4.tar.gz
      .
      .
      .
file0.22.tar.gz

#second directory
/directory2/files

textfile.num1.tar.gz
textfile.num2.tar.gz
textfile.num3.tar.gz
textfile.num4.tar.gz
        .
        .
        .
textfile.num22.tar.gz

In the first directory, I have 242 files in total. In the second directory I have 22 files.

I have written a simple nested for loop that uses script.py, as shown below. This loop works, but it has a caveat.

for z in `seq 0 10`; do
for i in `seq 1 22`; do python script.py --l2 --bfile ../directory2/textfile.num${i}.tar.gz --secondfile file${z}.num${i} --out file${z}.${i} --print-snps;done;done

If you notice, I have hardcoded file. Is there a way to run this without having to type in the filename?

The mapping logic is simple - files with the same "num" in the filename must map to one another. So:

file0.num1.tar.gz, file1.num1.tar.gz ... file10.num1.tar.gz must map to textfile.num1.tar.gz. And as a second example.

file0.num2.tar.gz, file1.num2.tar.gz ... file10.num2.tar.gz must map to textfile.num2.tar.gz

My loop is accomplishing this already, but I want to be able to write it without having to write file in the loop.

UPDATE:

I have gotten flagged for posting a duplicate question (I asked a somewhat similar question here: Nested for Loop In Directory). My previous question asked how I can use variables instead of filenames to run a loop. This question asks how I can use variables given that my loop runs on two separate directories .

Your Answer

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

Browse other questions tagged or ask your own question.