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

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


Just redirect the stderr to /dev/null:

cat file1 file2 .... 2>/dev/null

If one or more files don't exist, then cat will give an error which will go to /dev/null and you'll get the desired result.


grep -hs ^ file1 file2 ....

Unlike cat has zero return code. Option -h disables file name print, option -s disables file error reporting, ^ matches all lines.


zcat `ls *.rpt.gz | grep -E '_(max|min)\.rpt\.gz$'` | gzip > temp.rpt.gz

Bit of a hack, but then so is the shell :-P