#!/bin/bash
file=$1
v=0
if [ $# -ne 1 ]
then
echo "$0 fileName"
exit 1
fi
if [ ! -f $file ]
then
echo "$file not a file"
exit 2
fi
while read -n 1 c
do
l=$(echo $c | tr [:upper:] [:lower:])
[[ "$l" == "a" || "$l" == "e" || "$l" == "i" || "$l" == "o" || "$l" == "u" ]] && (( v++ ))
done < $file
echo "Vowels : $v"
echo "Characters : $(cat $file | wc -c)"
echo "Blank lines : $(grep -c '^$' $file)"
echo "Lines : $(cat $file|wc -l )"
OUTPUT:
file=$1
v=0
if [ $# -ne 1 ]
then
echo "$0 fileName"
exit 1
fi
if [ ! -f $file ]
then
echo "$file not a file"
exit 2
fi
while read -n 1 c
do
l=$(echo $c | tr [:upper:] [:lower:])
[[ "$l" == "a" || "$l" == "e" || "$l" == "i" || "$l" == "o" || "$l" == "u" ]] && (( v++ ))
done < $file
echo "Vowels : $v"
echo "Characters : $(cat $file | wc -c)"
echo "Blank lines : $(grep -c '^$' $file)"
echo "Lines : $(cat $file|wc -l )"
OUTPUT:

Words with vowel in a file
ReplyDeletev=0;for i in `cat test.txt`;do echo $i|egrep 'a|e|i|o|u' 2> /dev/null && ((v++)); done;echo $v;
No Vowel words in a file
v=0;for i in `cat test.txt`;do echo $i|egrep -v 'a|e|i|o|u' 2> /dev/null && ((v++)); done;echo $v;
It's showing syntax error can you please write the correct program
ReplyDelete