Saturday, April 27, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 1221  / 1 Year ago, tue, may 2, 2023, 6:06:09

I sometime need to check some logs and I do this with this command:



egrep -o "success|error|fail" <filename> | sort | uniq -c


Sample input:



test error on line 10
test connect success
test insert success
test started at 00:00
test delete fail


Sample output:



1 error
1 fail
2 success


I would like to know if someone knows a way to do this with a shorter command?



Before you ask why I would like to do this with an different command... No special reason, I'm just curious :)


More From » command-line

 Answers
3

Here is the awk way of doing it



awk 'BEGIN{RS=" "}/success/{s++}/fail/{f++}/error/{e++}END{print "Success:"s" Failed:"f" Error:"e}' abc


But all these one liners will be bit lengthier than our good old grep


[#35509] Wednesday, May 3, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
itchlos

Total Points: 486
Total Questions: 115
Total Answers: 110

Location: Macau
Member since Fri, Apr 28, 2023
1 Year ago
;