Posts

Showing posts from February, 2014

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 - q E "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.