I have a file that lists 5 lines of random words "See spot" "See pot run", etc each on a new line. I was able to create code that counted the number of times each word appears in the file and sorted properly.
4 Spot 3 run 2 see 1 sees 1 Run 1 Jane
Code I used:
cat "FILENAME" | tr ' ' '\n' | sort -n | uniq -c | sort -r
I put each word on a new line, sorted, then counted unique values and sorted again. Now I have to take that count but with this output:
3 1 1 2 1 3 1 4
This means there are 3 words with a count of 1, 1 word 2, 1 word 3, 1 word 4.
I am having 2 problems. 1 is how can I get a count of the first column which is already a count from uniq -c. The second problem is deleting the words in the second column and replacing with the original count of 1, 2 ,3, 4.