I want to grep
logs for exceptions and identify unique with their counts
Following is sample input
[msisdn:123][trxId:1234] | subscriptions | java.lang.Exception: this msidn NOT found
[msisdn:432][trxId:1212] | subscriptions | java.lang.Exception: this msidn NOT found
[msisdn:232][trxId:3232] | subscriptions | java.lang.Exception: this msidn NOT found
I used following and it shows duplicate with count
grep -i exception my.log| cut -d'|' -f2- | uniq –c
its shows results as expected, but i loose first part which contain msisdn and trxid, then i used following
grep -i exception my.log | sort -u -k 2,3 -t'|'
it shows unique results with sample line and on base of that sample line which contained msisdn and trxid I can troubleshoot.
Now how I can get count with my last command used?
This should work:
grep -i exception my.log | sort -k 2,3 -t'|' | uniq -c -f 1
Output:
3 [msisdn:123][trxId:1234] | subscriptions | java.lang.Exception: this msidn NOT found