1
$\begingroup$

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??

$\endgroup$
1
  • 4
    $\begingroup$ 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. $\endgroup$
    – terdon
    Apr 7, 2023 at 11:51

2 Answers 2

2
$\begingroup$

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.

$\endgroup$
1
$\begingroup$

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.

$\endgroup$

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.