Thursday, December 15, 2022

Find the number of repeatition of each word in a file using bash script

 #!/bin/bash
#input="./maharshi.txt"
#xyz=$1
#while read -r line
#do
#echo -e "$line"
#done <$xyz
declare -A words
file=$(cat ./maharshi.txt)
for line in $file
do

#echo -e "$line"
for word in $line
do
((words[$word]++))
done
done

for i in "${!words[@]}"
do
echo "$i " "${words[$i]}"
done



No comments:

Post a Comment