I have two directories with files in them.

dir_one contains files with names like :


dir_two filename pattern looks like this:


I wrote some R script which does something with the files. In order to run the script I have to run the following command:

Rscript interpolation.R 10.recode.vcf.mapgenetic_map_GRCh37_chr10.txt

Now I want to run this script 22 times, but I cannot figure out a way to match two files in different directories.

So far I only figured how to extract the common number from a filename:

for i in ./map_files/*
        echo ${i} ${i} | cut -d'/' -f 3 | cut -d'.' -f 1

I am not sure what to do next... Can anyone advice?

  • Should there be a space between map and genetic in your script run string? You need to tell us more about the contents of the directories (dir_one, dir_two and map_files) and explain the pairing criteria before we can help.
    – AFH
    Dec 14, 2015 at 14:49
  • Pairing criteria is a number. Number 10 in the example.
    – YKY
    Dec 14, 2015 at 15:00
  • Both directories contain bunch of filenames. Within the directory file names differ only by number (10 in the example, so in place of 10 there will be 9, 7, 22 and so on).
    – YKY
    Dec 14, 2015 at 15:02

1 Answer 1


It seem like I figured it out. I used bash parameter expansion like so:


for i in ./map_files/*
        Rscript interpolation.R $i ./genetic_map_HapMapII_GRCh37/*chr$t.*
  • 1
    I couldn't have worked this out from the information you gave: I infer that map_files is dir_one, but you didn't say so; and the answer string does not match the example in your question. Please take more care if you ask any future questions.
    – AFH
    Dec 14, 2015 at 15:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .