#!/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 )"
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics via:
- RSS feed or Weekly email newsletter
- 12 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
#!/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
i used grep command but it give wrong output .. count vowel and consonant in file
i think i search only for one time
no need for the loop in counting vowels…
grep -o “[AEIOUaeiou]” $file|wc -l
…will do the trick
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
why was “exec 3<&0" added to the above script..
I mean what's its use??
Hello,
give me a suggestion to
print the word containing vowel
Hello Aswin Triadhi
you can easily replace the word with sed using the following command
sed ‘s/stopped/idle/g’
this will replace the word globally…
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
what is 3<&0?
Man you need to add;
ı
ö
ü
for vowels too.
Thank you for script.
Vivek, always learn something on your site..thanks
btw:
echo “Vowles : $v” (sic) “Vowels”
@Jim,
Thanks for the heads up!