How to sort a file with string lines by the number of a specific symbol in the line?
- by SpacyRicochet
Say I have a large plaintext file with a string on every line. The string only consists of alphabetical characters, except for underscores _, which divide the strings in syllables.
I want to sort the text file by the amount underscores in the string. Bonus points for putting every group of X underscores in their own file.
Example:
hel_lo
hi
su_per_u_ser
o_ver_flow
would sort into:
hi
hel_lo
o_ver_flow
su_per_u_ser
I've tried doing this with regex, but I've yet to find a proper way of counting the underscores (regex confuses me thoroughly).
Anyone know how I could handle this?