Unix - Effective use of Tail / Find / Grep / Sed / Awk with Application logs

To see only lines containing an error / exception in last 5000 lines.


tail -5000 /opt/WebSphere/AppServer/profiles/application/logs/SystemOut.log | grep -i "FileNotFoundException"

To see lines containing any of the multiple errors / exceptions in running logs -


tail -f /opt/WebSphere/AppServer/profiles/application/logs/SystemOut.log | egrep "(WSWS3713E|WSWS3734W|WSVR0605W|javax.net.ssl.SSLHandshakeException|ThreadMonitor)"

To see Error Snipets in running logs.


tail -f /opt/WebSphere/AppServer/profiles/application/logs/SystemOut.log | sed -n '/ERROR/,/EST/p'

To get all error / exception snippets in another file.


sed -n '/ERROR/,/EST/p' /opt/WebSphere/AppServer/profiles/application/logs/SystemOut.log* >> newFile.txt

To find occurences of a particular error in last n days.


find /opt/WebSphere/AppServer/profiles/application/logs/ -iname "SystemOut*" -mtime -7 -exec zgrep "FileNotFoundException" {} \; >> logAnalysis.txt

To count number of error / exception occurences in a log file.


sed -n '/ERROR/,/EST/p' /opt/WebSphere/AppServer/profiles/application/logs/SystemOut.log | grep "LogicBlockSetupException" | wc -l

To report the file size of all files bigger than 2 mb and older than 30 days.


find . -type f -size +4096 -atime +30 -exec \du -sk '{}' \;