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

Qlikview tips - how to escape characters and space LOAD INLINE table