I have two directories with files in them.

dir_one contains files with names like :

10.recode.vcf.map

dir_two filename pattern looks like this:

genetic_map_GRCh37_chr10.txt

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/*
do
        echo ${i} ${i} | cut -d'/' -f 3 | cut -d'.' -f 1
done

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 '15 at 14:49
  • Pairing criteria is a number. Number 10 in the example. – YKY Dec 14 '15 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 '15 at 15:02

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

#/bin/bash

for i in ./map_files/*
do
        t=${i##*/}
        t=${t%%.*}
        Rscript interpolation.R $i ./genetic_map_HapMapII_GRCh37/*chr$t.*
done
  • 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 '15 at 15:49

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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