cat file | grep 'expression'
is the shell analogue of the SQL query select * from (select * from table) as q where column like '%expression%'
...except that a decent query optimizer will collapse the extraneous inner query. Bash doesn't know how to do that.It's also more expensive:
# wc -l /var/log/secure
97845 /var/log/secure
# time cat /var/log/secure | grep root > /dev/null
real 0m1.600s
user 0m1.517s
sys 0m0.294s
# time grep root /var/log/secure > /dev/null
real 0m1.275s
user 0m1.237s
sys 0m0.036s
That's an extra .3-and-change seconds, or over 25% longer, on a 98k line file. Scale that up to a multi-million line ngnix log file, and I'd actually say it's a worse than useless use of cat.