bash string match on specific lines using grep

Check the string contains "error" in the last line of a file:
tail -1 error.log | grep -E "Error" && echo "yes"
or
grep Error error.log  |  tail -1
or
[[ $(tail -1 error.log | grep -E "Error") ]] && echo "yes"
note: the "[[" and "[" usage can be really different, reference here
or
tail -1 error.log | grep -qE "Error" && echo yes 
note: -q is used to silence the output of grep.

The first 2 cmds will at the same time return the "error" lines in the file, and the last 2 cmds return only  "yes" as the result.

Comments

Popular posts from this blog

install ipython in Cloudera VM using pip

install postgreSQL in ubuntu 16.04

Install MYSQL 5.6 in ubuntu 12.04/14.04 and set password and remote access