Search code examples
shellloopsunixgeneticsgenome

Unix. Loop through Plink files with same names but different chromosome numbers. Produce output


I have basic knowledge of Unix. I have a list of 22 files with this name pattern: chr1_ASI, chr2_ASI, chr3_ASI...chr22_ASI.

I want to loop through them using this Plink command in the OS X Terminal:

./plink --file /path/chr1_ASI --chr 1 --make-bed --out /path/chr1_ASI_filtered

And then the same for chromosomes 2-22.

I want to simplify this script using a for loop in Unix. This is what I have.

for i in {1..22}; do ./plink --file /path/chr${1}_ASI --chr ${i} --make-bed --out /path/chr${i}_ASI_filtered; done

But this is not working. I am probably doing some basic mistake. Thank you in advance.

EDITED: as someone noticed, my mistake was just writing chr${1}_ASI instead of chr${i}_ASI. Otherwise the script runs perfectly fine.


Solution

  • Try changing: /path/chr${1}_ASI to /path/chr${i}_ASI