Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unix cat multiple files - don't cause error if one doesn't exist?

I'm trying to cat a bunch of files, some of which may not exist. Now that's ok if some of them don't exist, but I don't want cat to return an error in this case, if possible. Here's my call:

zcat *_max.rpt.gz *_min.rpt.gz | gzip > temp.rpt.gz

When this command is run, either a bunch of files matching *_max.rpt.gz will exist, or *_min.rpt.gz will exist. If the other doesn't exist, I don't care, I just want to concatenate what I can. But I'm getting an error message which stops the rest of my code from running.

Anything I can do? Thanks.

like image 723
JDS Avatar asked Oct 10 '12 21:10

JDS


People also ask

Can the cat command be used to view multiple files?

cat command allows us to create single or multiple files, view content of a file, concatenate files and redirect output in terminal or files.

How do you cat multiple files in Unix?

Type the cat command followed by the file or files you want to add to the end of an existing file. Then, type two output redirection symbols ( >> ) followed by the name of the existing file you want to add to.

Does cat overwrite file?

The key takeaway from this section is that we use cat > FILENAME to create or overwrite a file. Additionally, we can use cat >> FILENAME to append to a file that's already there. Then after typing in the text we want we use CTRL + D to exit the editor, return to the command line, and create the file.

What is cat << in Linux?

Cat is short for concatenate. This command displays the contents of one or more files without having to open the file for editing. In this article, learn how to use the cat command in Linux. A system running Linux. Access to a terminal window / command line.


1 Answers

[ -f file.txt ] && cat file.txt

like image 163
user3167916 Avatar answered Oct 13 '22 03:10

user3167916