This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Problem with " Argument list is long"

I am facing a problem with concatenating file with cat command as I have to concatenate120441 files together. In test directory, I have 120441 subdirectories which start with GC and every subdirectory contain a result_tab.txt file which I need to concatenate. I use the following command cd test cat GC*/result_tab.txt > result_all.txt

But error occurs " Argument list is too long". Then I use the following command

find  . -name 'result_tab.txt' -exec cat {} + > result_all.txt

But when I see the result_all.txt file there is nothing. Any solution? I tried the following for loop too. But not working

for f in GC*/result_tab.txt; do cat "$f"; done > results_all.txt
sequence

1 answer

Even as I question myself about the usefulness of concatenating 120441 "result_tab.txt" into one, here is one solution:

 find  . -name 'result_tab.txt' -exec cat {} \; >> results_all.txt

Here is another, with a loop:

for i in GC*/result_tab.txt; do cat "$i" >> results_all.txt; done

Make sure "results_all.txt" does not exist, otherwise output would be appended to the already existing file.

Log in to answer this question.