I am looking for a shell script that accepts a list of file names as its arguments, counts and reports the occurrence of each word that is present in the first argument file on other argument files.
I am pretty much sure how to count the occurrences of a word with respect to one file.
That is by using this trick :
$ tr ' ' '\n' < FILE | grep -c WORD
I am stuck when it gets to
n number of files.
This is what I have come with so far :
#!/bin/bash if [ $# -lt 2 ] then echo "Very less arguments bro." fi search_file=`tr '\n' ' ' < $1` # Make the first file in to a sequence of words. for other_file in "$@" do if [ $other_file = $1 ] then continue fi # Modify this file such that each space turns in to a newline tr ' ' '\n' < $other_file > new_temp_file for search_word in $search_file do word_freq=`grep -c $search_word new_temp_file` echo "Word=$search_word Frequency=$word_freq" done done