Iam back with another shell script written for my sis as part of her assignment. This time what i wanted to do is to count the unique words in a file and to print it in alphabetical order. For that i iterated through the words in the given file using for loop, filtered out the unique words using sort -u and counted it using wc -l.
#!/usr/bin/bash echo Enter the filename read fn for WORD in $(cat $fn) do echo "$WORD" done | sort -u | wc -l for WORD in $(cat $fn) do echo "$WORD " done | sort -u
Hope this will help someone to do his/her assignment 😀
thanks! that’s really useful
Nice to know that it helped someone 🙂
I would LOVE to know how to do this, as I’m currently working on a short story, but have no specialized computer skills.
Any advice?
What you want to know?
Well, I have no knowledge of code, etc., and was hoping to be able to copy/paste a text into a “box,” push the Start Button and have the result show up as if by magic, like the N+7 Generators where you enter text and it changes every noun to the 7th one up in the dictionary (which is also fun).
Which operating system you are using?
Windows 7
Hi Sagar
Can u please suggest a good site/link where I can find shell script examples, like the one you posted.
more fn | sort | uniq -u | wc -l
This is more easy..?? to count the uniq words in a file.
I found this works: cat fn | tr -d “[:punct:]” | tr -d “[:digit:]” | tr ” ” “\n” | tr “[:upper:]” “[:lower:]” | sort | uniq -u | wc -l