How can pipes and grep and wc be combined to just give a count of the phrase “syntax ok”

587 Views Asked by At

How can pipes and grep and wc be combined to just give a count of the phrase “syntax ok”

Something like the following…

cd /usr/IBMIHS/bin/ |
apachectl -t -f /usr/IBMIHS/conf/AAA/httpd.conf |
apachectl -t -f /usr/IBMIHS/conf/AAA/siteAA.conf |
grep "^Syntax OK" | wc 
1

There are 1 best solutions below

10
Gilles Quénot On

Simply via grouping commands with curly brackets, and use grep -c:

{
    apachectl -t -f /usr/IBMIHS/conf/AAA/httpd.conf
    apachectl -t -f /usr/IBMIHS/conf/AAA/siteAA.conf
} |& grep -c "Syntax OK"

From man grep

-c, --count
Suppress normal output; instead print a count of matching lines for each input file. With the -v, --invert-match option (see below), count non-matching lines.