regex - Pattern matching in if statement in bash -




i'm trying count words @ least 2 vowels in .txt files in directory. here's code far:

#!/bin/bash  wordcount=0   in $home/*.txt cat $i | while read line     w in $line         if [[ $w == .*[aeiouaeiou].*[aeiouaeiou].* ]]             wordcount=`expr $wordcount + 1`         echo $w ':' $wordcount       else         echo "in else"     fi     done done echo $i ':' $wordcount wordcount=0 done 

here sample txt file

last modified: sun aug 20 18:18:27 ist 2017
remove ppas
sudo apt-get install ppa-purge
sudo ppa-purge ppa:

the problem doesn't match pattern in if statement words in text file. goes directly else statement. , secondly, wordcount in echo $i ':' $wordcount equal 0 should value.

using grep - pretty simple do.

#!/bin/bash  wordcount=0 file in ./*.txt count=`cat $file | xargs -n1 | grep -ie "[aeiou].*[aeiou]" | wc -l` wordcount=`expr $wordcount + $count` done  echo $wordcount 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -