I am new to bash shell programming. I need to make a program to count no. of tab characters and no. of new line characters from a file. I have made following script, which seems to be unable to count \n and \t. how to read such special characters from a file. it was too easy in C language.
I need to count character by character, so can't use sed, awk etc.
while read -n1 char; do
nc=$(($nc + 1)) # nc : no of characters
if [[ $char = '\n' ]]; then
nl=$(($nl + 1)) # nl : no. of lines
else if [[ $char = '\t' ]]; then
nt=$(($nt + 1)) # nt : no. of tabs
done < $1
Any help is much appreciated.