I have this code in bash. I wanted to ask, how can I change this code that for example when if gets to the word Aaa: ----> the output of the length of this word will be 3 and not 4 (I want it to ignore other chars and only count the letters). Thanks for the help!
#!/bin/bash
words=$(tr -s '[.,: ] ' '\n' < "$1")
longest_length=0
for word in $words
do
current_length=${#word}
if ((current_length > longest_length))
then
longest_length=$current_length
longest_word=$word
fi
done
echo 'The longest word is %s and its length is %d.\n' "$longest_word" "$longest_length"