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

CC BY-SA 4.0
2020-01-21T19:29:07.280Z
2020-01-21T19:29:07.280Z
Stuber
<p>First of all you are getting an error because you are missing a <code>then</code> in the third line of your code and then a <code>fi</code> to close the <code>if</code>. It should be:</p>

<pre><code>for i in *.vcf
do if grep -q <span class="math-container">$i 1.txt; then
    cp *$</span>out* /temp/hgig/fi1d18/TRG45/snp/snp/TRG/pre/
fi
done
</code></pre>

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

<pre><code>while IFS= read -r line; do mv "$line"*.vcf some-directory; done &lt; file-list.txt 
</code></pre>

CC BY-SA 4.0
2020-01-05T19:34:42.530Z
2020-01-06T09:38:19.013Z
2020-01-06T09:38:19.013Z
haci
<p>I have a list of vcf files; I also have a list of names in a txt file like</p>

<pre><code>LP6005409-DNA_F01
LP2000325-DNA_A01
LP6005409-DNA_E02
LP6005500-DNA_C03
</code></pre>

<p>What I have in this txt files are part of name of each vcf files</p>

<p>I want to move .vcf files having these in their name to a separate folder</p>

<p>I done</p>

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

<p>How I can complete this task?</p>

<p>Thank you</p>

<bash><linux>
Moving file based on their names
# Moving file based on their names

(Asked by: username_0 on 2020-01-05)

I have a list of vcf files; I also have a list of names in a txt file like
LP6005409-DNA_F01
LP2000325-DNA_A01
LP6005409-DNA_E02
LP6005500-DNA_C03

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

**Tags:** bash, linux

---

## 2 answers

### Answer by username_2 on 2020-01-05. Score: 4 | Accepted answer

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/
fi
done

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


---

### Answer by username_1 on 2020-01-21. Score: 1

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


---

