I used the below command
nohup cat fastp-filtered/OZBenth*_R1.fastp.fq.gz > fastp-filtered-merged4racon/merge_R1.fq.gz > merge_R1.out.log 2>&1 &
but unfortunately, the output went to
merge_R1.out.log and not to
What did I miss?
Redirections are processed in a left-to-right fashion.
When executing a command like
somecommand >f1 >f2 >f3
the shell will first create or truncate (empty) the file
f2 and lastly
f3. Then it starts
somecommand with its standard output connected to
To save the output of a command to multiple files, you would have to duplicate the data for each output file. This is easiest done with
somecommand | tee f1 f2 >f3
This sends the output of
tee which duplicates it into the two files
tee utility also produces the same data on its own standard output, and in the command above we simply redirect this into
In your case, you would use
nohup cat fastp-filtered/OZBenth*_R1.fastp.fq.gz 2>&1 | tee fastp-filtered-merged4racon/merge_R1.fq.gz >merge_R1.out.log &
2>&1 makes the error stream from
cat be sent to
tee as well (this may not be wanted as any errors would corrupt the resulting archive).
tee truncates its output files, just like
> would do. Use
tee with its
-a option to append data to an output file.
It's unlikely that you actually meant for all output from
cat to be written to two files though, so assuming that you want to save the errors to the log file and the concatenated archives to the output file, you would instead do
nohup cat fastp-filtered/OZBenth*_R1.fastp.fq.gz \ >fastp-filtered-merged4racon/merge_R1.fq.gz \ 2>merge_R1.out.log &
without the need for using
tee at all.