Shell Script To Count Vowels, Blank Spaces, Characters, Number of line and Symbols

in Categories Academic, Decision Making, String Management last updated February 20, 2009
#!/bin/bash
# Shell program to count
# Vowels, blank spaces, characters, number of line and symbols
# A, E, I, O, U 
# --------------------------------------------------------------------
# This is a free shell script under GNU GPL version 2.0 or above
# Copyright (C) 2005 nixCraft project.
# Feedback/comment/suggestions : http://cyberciti.biz/fb/
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
 
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
 
# read vowels
exec 3<&0
while read -n 1 c
do 
  l="$(echo $c | tr '[A-Z]' '[a-z]')"
  [ "$l" == "a" -o "$l" == "e" -o "$l" == "i" -o "$l" == "o" -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 )"

Share this on:

12 comment

  1. #!/bin/bash
    ### Script to count vowels, no.of lines,blank spaces, words in a given file
    echo " Enter the file name "
    read a
    char=`cat $a | wc -m`
    echo "The number of characters in file are:" $char
    line=`cat $a | wc -l`
    echo "The number of lines are:" $line
    vow=`cat $a | grep -o "[aAeEiIoOuU]" |wc -l`
    echo "The number of vowels are:" $vow
    space=`cat $a | grep -o " "| wc -l`
    echo "The number of blank spaces are:" $space

  2. I need to count number blank records for particular column.

    total record in a file is 100
    total blank in column1 is 40 or so.

    How to get this?

    Thanks in advance
    Umar

  3. Halo viviek

    How to replace a word in file text
    I have printers.conf in /var/cups/printers.conf
    and I want replace the State Stopped to State Idle with shell script
    example

    Info MY_PRINT
    DeviceURI hp:/net/hp_LaserJet_4250?ip=88.8.8.223
    State Stopped
    StateTime 1254732779
    Accepting Yes
    Shared Yes
    JobSheets none none
    QuotaPeriod 0
    PageLimit 0
    KLimit 0
    OpPolicy default
    ErrorPolicy stop-printer

    I want replace the State Stopped with State Idle, how ?
    regards

Leave a Comment