Thursday, April 12, 2012

unix - breakdown of how many lines with number of character occurrences

Is there an inbuilt command to do this or has anyone had any luck with a script that does it?



I am looking to get counts of how many lines had how many occurrences of a specfic character. (sorted descending by the number of occurrences)



For example, with this sample file:



gkdjpgfdpgdp
fdkj
pgdppp
ppp
gfjkl


Suggested input (for the 'p' character)



bash/perl some_script_name "p" samplefile



Desired output:



occs     count
4 1
3 2
0 2




No comments:

Post a Comment