Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- string=$(cat $1 | sed -z 's/\s\s/ /g' | sed 's/[ ][ ]*/ /g')
- allowed="aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZåÅäÄöÖ"
- test_char() {
- is_allowed=0
- if [[ $1 == [$allowed] ]]; then
- is_allowed=1
- fi
- echo $is_allowed
- }
- letter_count=0
- word_count=1
- for (( i=0; i<${#string}; i++ )); do
- if [[ ${string:$i:1} == " " ]]; then
- word_count=$((word_count+1))
- else
- was_allowed=$(test_char ${string:$i:1})
- letter_count=$(($letter_count+$was_allowed))
- fi
- done
- if [ $letter_count -gt 0 ]; then
- echo Sanoja: $word_count
- echo Kirjaimia: $letter_count
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement