Wednesday, December 21, 2022

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

#!/usr/bin/bash
echo "Please enter a sentence"
read sentence
for word in $(echo $sentence|xargs -n 1 |sort -u )

do
#occurance=$(echo $sentence | grep -i -o "$word"  | wc -w)

echo -e "$word-$(echo $sentence | grep -i -o "$word"  | wc -w)"



done

No comments:

Post a Comment