Friday, March 7, 2014

Grep command in linux

Grep search with multiple strings

search two words in a single line  
grep -in "word1.*word2" /var/log/messages

-i to ignore case

search multiple words in a log file front and back
grep -A 2 -B 2 "word1 \| word2 \| word 3"

-A, bring 2 lines above
-B, bring 2 lines below
Eg:
tailf /var/log/messages | grep -A 5 -B 5 "Service Unav\|DENIED\|Temporarily\|conges\|Too many\|Time-out"

you can use tail command to monitor the logs. tailf and tail -f both are same

No comments:

Post a Comment

CSS tricks

Mixed paint in background: background: linear-gradient(to right, #b6e358, #38b143) Grid view: display: grid; grid-template-columns: a...