This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Cat command to combine multiple fastq.gz file

I am trying to combine 4 fastq.gz files in to one big file using following command.

cat *.fastq.gz > File_Big.fastq.gz

However Every time I got following error

Error: object '.fastq.gz' not found

I made sure that I am working in correct directory.

Anyone have any idea where I am going wrong?

Thanks

linux

Is there a space between your * and .fastq.gz?

No there is no space between * and .fastq.gz

What is the output of ls -1 *.fastq.gz? And the output of ls -1?

Sorry I am new to R.

I ran ls -1 *.fastq.gz and got following output Error: object '.fastq.gz' not found

Then I ran ls -1 and got following output Error in ls - 1 : non-numeric argument to binary operator

Sorry I am new to R.

this is not R , this is bash.

Ah, that explains so much. This doesn't go in R. This goes in your command line terminal.

Thank you for the help. Problem is resolved. I am able to combine it using terminal.

Do not use .fastq.gz for output extension if output is in same directory if you are running cat *.fastq.gz > File_Big.fastq.gz in shell. @ kam23lesh

Thank you for the reply. I will keep this in mind.

Although it is better to be safe than sorry, most likely one won't have problems with cat *.fastq.gz > File_Big.fastq.gz. Bash-related shells first parse the glob, only then they create the output file. A little test:

echo "1" > 1.txt
echo "a" > a.txt
cat *.txt > a1.txt
nl *.txt > a1_nl.txt

Now cat a1.txt shows:

1

a

And cat a1_n1.txt shows:

 1  1
 2  1
 3  a
 4  a

I performed the test above in bash and zsh, which I believe are the two most used shells currently.

C shells create the output file before parsing the glob, and indeed cat *.fastq.gz > File_Big.fastq.gz would cause a big problem, probably filling the disk.

This works OK with sh too (sh is POSIX compliant and the most hidden/painful of non C shells). However, I recommend against this as it can prove dangerous for beginners (or even pros with a few unknowns in shell config). In general, do not redirect an out or err stream to a file that matches a glob used by an in stream.

1 answer

You are using this command inside R.

Don't use R directly, using a linux shell. Like bash. https://www.tldp.org/LDP/Bash-Beginners-Guide/html/Bash-Beginners-Guide.html

Thank you for the help. Problem is resolved. I am able to combine the files using terminal.

If an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one if they work.

Upvote|Bookmark|Accept

Log in to answer this question.