• Arun Kumar

Shell Script to Count Characters

Linux shell script allows user to create a script that read the files and make the report of Vowels, Blank Spaces, Characters, Number of lines, and symbol.

vi count_characters.sh
# !/bin/bash 

if [ $# -ne 1 ]
	echo "$0 fileName"
	exit 1
if [ ! -f $file ]
	echo "$file not a file"
	exit 2
# read vowels
exec 3<&0
while read -n 1 c
  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 )"

Here is the sample output of the above script

More ways to use count in file

  • You can use it without a loop to count vowels.

  • You can also use wc and case statements to execute.


Recent Posts

See All

Oracle 19c Installation on Linux

Oracle 19c adds more features to Oracle database and this article demonstrates Oracle 19c installation on Linux 7. We will be using Oracle Linux 7 and Oracle Database 19.3 softwares for this activity.

Basic Linux Commands

This article describes basic Linux commands that you must know as a system or database administrator. Below commands in Linux help you manage any Linux server fast and smoothly. Linux Command List Che

Linux Firewall with iptables and firewalld

In this article will be covering details regarding iptables and firewalld which helps in Linux firewall management. We will also be looking at how to enable specific ports (1521 for Oracle) inside ipt