I have a list of vcf files; I also have a list of names in a txt file like


What I have in this txt files are part of name of each vcf files

I want to move .vcf files having these in their name to a separate folder

I done

[fi1d18@cyan01 TRG]$ for i in *.vcf
> do if grep -q $i 1.txt;
> cp *$out* /temp/hgig/fi1d18/TRG45/snp/snp/TRG/pre/
> done
-bash: syntax error near unexpected token `done'
[fi1d18@cyan01 TRG]$

How I can complete this task?

Thank you


2 Answers 2


First of all you are getting an error because you are missing a then in the third line of your code and then a fi to close the if. It should be:

for i in *.vcf
do if grep -q $i 1.txt; then
    cp *$out* /temp/hgig/fi1d18/TRG45/snp/snp/TRG/pre/

And I guess the one-liner below achieves what you are trying to do:

while IFS= read -r line; do mv "$line"*.vcf some-directory; done < file-list.txt 

for i in $(cat text.txt); do cp -v *${i}*vcf mydir; done


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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