(I am looking for a better solution in Perl for this problem).
Here is the abstract of the goal: I have a file output.txt, it contains Unexpected exception : which is followed by different exceptions... For instance, it looks like
...
Unexpected exception : exception1
...
Unexpected exception : exception2
...
Here is a Perl script which summarizes output.txt by listing what exceptions are raised and their number of occurrence:
perl -lne '$a{$2}++ if (/^(Unexpected exception) : (.*?)\s*$/); END { for $i (keys %a) { print " ", $i, " ", $a{$i} } }' $1
The result looks like:
exception2 : 15
exception3 : 7
exception1 : 9
...
Now I would like to improve this script, so that the exceptions could be listed in an alphabetical order:
exception1 : 9
exception2 : 15
exception3 : 7
...
Does anyone know how to change this script to achieve this goal?
Additionally, I may want to list the exceptions in a decreasing order of the occurrence:
exception15 : 20
exception2 : 15
exception1 : 9
exception3 : 7
...
Does anyone know to do it?
all that stuff | sortman sortwill answer your question.