Alternatives for 'egrep -o "success|error|fail" <filename> | sort | uniq -c'
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
No, I think that you are as good as it gets. Naturally, you could do it with one perl script,
perl -nle 's/.*(error|fail|success).*/$1/ && $a{$_}++ ; END { print "$_ $a{$_}" for keys %a } ' test.txt
...but it is more complex and less intuitive.
Not much shorter, but since you don't really need the regular expression, there's fgrep
(grep -F
).
fgrep 'success
error
fail' "$filename" | sort | uniq -c
another way to write the same thing in bash:
fgrep $'success\nerror\nfail' "$filename" | sort | uniq -c
You could write a simple bash script and then call the script, like:
#!/bin/bash
egrep -o "success|error|fail" "$1" | sort | uniq -c
and save it as (for example) myscript.sh
. Then do a chmod +x myscript.sh
and you can call it like myscript.sh <filename>
.