I use the following ‘grep’ command to get the count of the string alert in each of my files at the given path:
grep 'alert' -F /usr/local/snort/rules/* -c
How do I sort the resulting output in desired order- say ascending order, descending order, ordered by name, etc. An answer specific to these cases is sufficient.
You may freely suggest a command other than grep as well.
Pipe it into sort. Assuming your filenames have no colons, use the “-t” option to specify the colon as field saparator. Use -n for numerical sorting.
Example:
should split lines into fields separated by “:”, use the second field for sorting, and treat this as numbers (so 21 is actually later than 3).