Reputation: 75
I have written this code for char, word, line count but I am not getting expected result. Can anyone help?
#!/bin/bash
echo "enter filename"
read filename
count=0
file=$filename
file="$(<$file)"
character="${#file}"
for ((i=0;i<character;i++))
do
echo "${file:i:1}"
(( count++ ))
done
echo "No of character =$count"
Upvotes: 0
Views: 31
Reputation: 3914
Use this script
echo Enter filename
read file
w=`cat $file | wc -w`
c=`cat $file | wc -c`
l=`grep -c "." $file`
echo Number of characters in $file is $c
echo Number of words in $file is $w
echo Number of lines in $file is $l
Upvotes: 1