Cat command to combine multiple fastq.gz file
1
1
Entering edit mode
5.6 years ago
kam23lesh • 0

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 • 9.1k views
ADD COMMENT
3
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
2
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

Sorry I am new to R.

this is not R , this is bash.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
2
Entering edit mode
5.6 years ago

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

ADD COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 2607 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6