<p>This should work</p>
<pre><code>xargs &lt; names.txt cat &gt; names.fasta
</code></pre>
<p>Or else try,</p>
<pre><code>cat names.txt | xargs cat &gt; newdir/names.fasta
</code></pre>
<p>What I think is within <code>names.txt</code> there's a typo or a missing file and that's what it's complaining about.</p>
<p>Perhaps try using</p>
<pre><code>ls &gt; tmp
cat names.txt | sort &gt; tmp2
diff tmp tmp2
</code></pre>
<p>If there are any differences that should pick it up.</p>

CC BY-SA 4.0
2023-04-06T16:45:42.107Z
2023-04-06T16:45:42.107Z
M__
<p>Just to address an edge case, run <code>dos2unix names.txt</code> first and then a modified version of @M__'s command</p>
<pre><code>cat names.txt | xargs -I v_file cat v_file &gt;&gt; names.fasta
</code></pre>
<p>Based on your edit, it looks like your working platform has different line endings compared to the platform on which <code>names.txt</code> was last edited/saved.</p>

CC BY-SA 4.0
2023-04-06T18:23:30.793Z
2023-04-06T18:23:30.793Z
Ram RS
<p>I have about 10 fasta files that I need to pull from a giant folder of other fasta files (has about 100 files). I have a list of the files I need in a .txt file separated by line and I want to pull out the 10 fasta files listed and combine them into one big file.</p>
<p>I tried this command at first:
<code>xargs &lt; names.txt cat &gt; names.fasta</code></p>
<p>But it gave me this error:
<code>cat: 'read_1.fasta'$'\r': No such file or directory</code></p>
<p>For all the files except the last read in the list which it managed to add to the <code>names.fasta</code> .</p>
<p>I'm not sure what the error message means given I can find the files in my folder so they should be there. I can do this manually but I know it'll take a while to do.</p>
<p><strong>EDIT</strong>: I changed the list to be separated by space and it actually pulled out all the files I needed! However, is there a way to account for reading in the names by newline instead of space??</p>

CC BY-SA 4.0
2023-04-07T11:51:17.097Z
Please always mention what operating system you are using. Your error suggests you are using Windows and have Windows line endings (`\r\n`) and that is essential information when trying to manipulate files and parse text.
terdon
<fasta><command-line>
Combine separate fasta files from a list.txt
# Combine separate fasta files from a list.txt

(Asked by: username_0 on 2023-04-06)

I have about 10 fasta files that I need to pull from a giant folder of other fasta files (has about 100 files). I have a list of the files I need in a .txt file separated by line and I want to pull out the 10 fasta files listed and combine them into one big file.

I tried this command at first:
`xargs < names.txt cat > names.fasta`

But it gave me this error:
`cat: 'read_1.fasta'$'\r': No such file or directory`

For all the files except the last read in the list which it managed to add to the `names.fasta` .

I'm not sure what the error message means given I can find the files in my folder so they should be there. I can do this manually but I know it'll take a while to do.

**EDIT**: I changed the list to be separated by space and it actually pulled out all the files I needed! However, is there a way to account for reading in the names by newline instead of space??

**Tags:** fasta, command-line
> **Comments:**
> **username_1**: Please always mention what operating system you are using. Your error suggests you are using Windows and have Windows line endings (`\r\n`) and that is essential information when trying to manipulate files and parse text.  

---

## 2 answers

### Answer by username_2 on 2023-04-06. Score: 2

This should work
xargs < names.txt cat > names.fasta

Or else try,
cat names.txt | xargs cat > newdir/names.fasta

What I think is within names.txt there's a typo or a missing file and that's what it's complaining about.
Perhaps try using
ls > tmp
cat names.txt | sort > tmp2
diff tmp tmp2

If there are any differences that should pick it up.


---

### Answer by username_3 on 2023-04-06. Score: 1

Just to address an edge case, run dos2unix names.txt first and then a modified version of @M__'s command
cat names.txt | xargs -I v_file cat v_file >> names.fasta

Based on your edit, it looks like your working platform has different line endings compared to the platform on which names.txt was last edited/saved.


---

