How to find unique words from linux file

I have a large file, the lines look like this: Text numbers, etc. [Man- (some numbers)] a lot of this Man-somenumbers is repeated in several lines, I want to count only unique Mans-words. I can’t use a unique file because the text before the words Man is always different on every line. How can I count only the unique words Man-somenumbers in a file?

+5
source share
1 answer

If I understand what you want to do right, then

grep -oE 'Man-[0-9]+' filename | sort | uniq -c 

gotta do the trick. It works as follows: First

 grep -oE 'Man-[0-9]+' filename 

isolates all words from a file matching the regular expression Man-[0-9]+ . This list is then passed through sort to get the sorted list that uniq needs, and then the sorted list is sent through uniq -c to count how often each unique Man- word appears.

+6
source

Source: https://habr.com/ru/post/1215814/


All Articles