Num Dist Wordsawk Write Awk Program Counts Number Distinct Words Input File Words Means Fi Q37099085

num-dist-words.awk

Write a awk program that counts the number of distinct wordsfrom the input file, where ‘words’ means the field values in a awkprogram with the default input field separator.

************* input file ************************

As an exercise for English students, generate a list of tenrandom words and have the student write a story that incorporatesthose words in the order they’re generated.

You could also take the hard work out of playing MadLibs but forthat you’ll need to separate out the parts of speech. There’sgenerators for each one, just jump over using the optionsbelow.

*************************************************


Answer


awk ‘{for(i=1;i<=NF;i++) a[$i]++} END {for(k in a) print k,a[k]}’ testfile

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.