Dear all
The objective is to write a bash shell script to read and count special
characters along with normal alphabetic characters for which I seek your help
in finding solution. The sample script for reading and counting number of
characters present in INPUT text file is attached. The special characters
exclusinvely are "?, - ". I am able to fulfill my requirement only for the
alphabetic characters and not for the special characters. The help in this
regard shall highly be appreciated & regarded.
with regards
s.mahalingam
#!/bin/bash
INPUT="/tmp/count_chars.txt"
# counter
A=0
G=0
C=0
T=0
#Make sure file name supplied
[ $# -eq 0 ] && { echo "Usage: $0 filename"; exit 1; }
#Make sure file exist else die
[ ! -f $INPUT ] && { echo "$0: file $INPUT not found."; exit 2; }
#the while loop, read one char at a time
while IFS= read -r -n1 c
do
#counter letter A,G,C,T
[ "$c" == "A" ] && (( A++ ))
[ "$c" == "G" ] && (( G++ ))
[ "$c" == "C" ] && (( C++ ))
[ "$c" == "T" ] && (( T++ )) && (( D=$A+$G+$C+$T ))
[ "$c" == "?" ] && (( ?++ ))
done < "$INPUT"
# while IFS= read -r -n1 c
# while [ "$c" == "?" ] && (( ?++ ))
#do
#count symbol ?
#[ "$H" == "?" ] && (( ?++ ))
# echo "$H = ?"
#done < "$INPUT"
echo "Letter counter stats:"
echo "A = $A"
echo "G = $G"
echo "C = $C"
echo "T = $T"
echo "Total No. of A,G,C,T = $D"
#echo "? = $?"
AGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCT-----???????-------??AGCTAGCTAGCTAGCTAGCTAGCT--??AGCCCTTTTAAAAAAAAA???----
_______________________________________________
To unsubscribe, email [email protected] with
"unsubscribe <password> <address>"
in the subject or body of the message.
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc