The file I have is called test
and it contains the following lines:
This is a test Test test test There are multiple tests.
I want the output to be:
test@3 tests@1 multiple@1 is@1 are@1 a@1 This@1 There@1 Test@1
I have the following script:
cat $1 | tr ' ' '\n' > temp # put all words to a new line
echo -n > file2.txt # clear file2.txt
for line in $(cat temp) # trace each line from temp file
do
# check if the current line is visited
grep -q $line file2.txt
if [ $line==$temp]
then
count= expr `$count + 1` #count the number of words
echo $line"@"$count >> file2.txt # add word and frequency to file
fi
done