Name Error Count Severity Info
Server1 not found 1025 MAJOR some info here
Server4 some error 1 MAJOR some info here
Server 2 another error 587 MINOR more info
Server3 not found 15 MAJOR more info
I have some code to sort on the Severity, however, I can't get the numerical sort on the count to work correctly. I try to sort it numerically first, and then by severity, but the numerical portion doesn't seem to work. Here is what I have:
RESULTS: It sorts on severity just fine, but doesn't sort on Count. Let me know if that doesn't make sense.
Desired outcome (notice the Count is from greatest to least within each sub-set of Severity)
Name Error Count Severity Info
Server1 not found 1025 MAJOR some info here
Server3 not found 15 MAJOR more info
Server4 some error 1 MAJOR some info here
Server 2 another error 587 MINOR more info
Thank you for the suggestion. It doesn't work 100%. I cut out sensitive fields, but this gives you an idea of the results:
CODE (Note the first filed is to just grab the title/headers of the columns):
for i in RecommendedActions CRITICAL MAJOR HIGH MEDIUM MINOR LOW; do
grep "$i" "$1" | sort -k3,3nr >> $OUT
done
RESULT:
ErrorCount Severity
372 MAJOR
578 MAJOR
31249 MAJOR
8306 MAJOR
16 HIGH
17 HIGH
3236 MINOR
367 MINOR
2 MINOR
19 MINOR
85721 LOW
564 LOW
729 LOW
128424 LOW
220 LOW
25516 LOW
5 LOW
343080 LOW
3705 LOW
158 LOW
92 LOW
I didn't know how to interpret the debug output. I tried throwing in -t "," into my sort and now it is working. Don't know why I need to do that, as I thought it was the default, but it seems to work with that in there..... (don't have commas anywhere in this doc other than as field separators)
sort -t "," -k3,3nr "$1" > $OUT
for i in RecommendedActions CRITICAL MAJOR HIGH MEDIUM MINOR LOW; do
grep "$i" "$OUT" >> $OUT2
done
Ok, The right time to learn how to use the '--debug' option?
sort -k3nr --debug <<<"Server1 not found 1025 MAJOR some info here"
sort: text ordering performed using simple byte comparison
sort: key 1 is numeric and spans multiple fields
Server1 not found 1025 MAJOR some info here
^ no match for key
___________________________________________
mismatch!
sort -k4nr --debug <<<"Server1 not found 1025 MAJOR some info here"
sort: text ordering performed using simple byte comparison
sort: key 1 is numeric and spans multiple fields
Server1 not found 1025 MAJOR some info here
____
___________________________________________
You see, a little dash appeared under the number?
This first key sorting rule worked. But there are more clues
sort -k4,4nr --debug <<<"Server1 not found 1025 MAJOR some info here"
sort: text ordering performed using simple byte comparison
Server1 not found 1025 MAJOR some info here
____
___________________________________________
That's ok
--- Post updated at 22:18 ---
Also
Try it like this
head -1 file
for i in CRITICAL MAJOR HIGH MEDIUM MINOR LOW; do
grep "$i" file | sort -k4
done
If the 'Error' field has an undefined number of spaces, you can set the necessary delimiters.
also you can separate and display the title at once
sed -nr '1p;s/\s([0-9]+)\s+([[:upper:]]+)\s/_\1_\2_/w file2' file1
for i in CRITICAL MAJOR HIGH MEDIUM MINOR LOW; do
grep "$i" file2 | sort -t_ -k2,2nr
done | tr _ ' '
if necessary remove delimiters '_' using the trailing 'tr' command