This is a test version of Biostars. For the public version, visit https://www.biostars.org.
cat more than 2k files into 1 file

Hai all,

I am trying to cat more than 2k files (inside containing multiple sequences) into 1 file.

I used cat */*.fasta > output.fasta

(*/* because all the files contain in directories).

But I got the error : Argument too long.

Anyone please help me

sequence unix

Hello peacezah!

We believe that this post does not fit the main topic of this site.

not related to bioinformatics

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

Why should you close this? It`s related to computer as well.?

I've closed this post as it's just a linux-related question. As an answer:

find ./ -name "*.fasta" | while read F; do cat ${F} >> result.txt; done

Shortest way:

find . -name \*fasta -exec cat {} \; > out.fa

1 answer

Try this:

-n is the number of chunks it should allow once, and -p for number of cat jobs to run simultaneously.

ls */*.fasta | xargs -n <int chunks> -P <int jobs> cat >> output.fasta

Geek_y, still argument list too long.. :(

While that would be safe with GNU Parallel, using -P with xargs is dangerous if you want to use the output: You are likely to end up with mixed lines. man parallel has this example showing the problem:

parallel perl -e '\$a=\"1{}\"x10000000\;print\ \$a,\"\\n\"' '>' {} \
  ::: a b c d e f
ls -l a b c d e f
parallel -kP4 -n1 grep 1 > out.par ::: a b c d e f
echo a b c d e f | xargs -P4 -n1 grep 1 > out.xargs-unbuf
echo a b c d e f | \
  xargs -P4 -n1 grep --line-buffered 1 > out.xargs-linebuf
echo a b c d e f | xargs -n1 grep 1 > out.xargs-serial
ls -l out*
md5sum out*

Log in to answer this question.