I want to combine 2 different cat
statements into a single cat
statement
cat /dir1/file1.cfg | grep -q "linux"
cat /dir1/file2.cfg | grep -q "linux"
is there an OR
operation that can be used here to do the grep -q "linux"
on 2 files?
I want to combine 2 different cat
statements into a single cat
statement
cat /dir1/file1.cfg | grep -q "linux"
cat /dir1/file2.cfg | grep -q "linux"
is there an OR
operation that can be used here to do the grep -q "linux"
on 2 files?
What have you tried so far?
How about:
cat /dir1/file1.cfg /dir1/file2.cfg | grep -q "linux"
or with a subshell:
(cat /dir1/file1.cfg; cat /dir1/file2.cfg) | grep -q "linux"
or just:
grep -q "linux" /dir1/file1.cfg /dir1/file2.cfg
These all give equivalent results. The last would be how I'd write it.
% (cat f1; cat f2) | grep -q "linux"
% (cat f1 f2) | grep -q "linux"
% grep -q "linux" f1 f2
There's really no need for cat
at all - grep
will happily take its input from multiple files; normally, you need to tell it not to prefix the file name to the output lines, but since you're using -q
, even that isn't necessary:
grep -q "linux" /dir1/file[12].cfg
(I've used a shell glob to save writing the repeated parts of the filename there).