Quote:
Originally posted by shyams75
Hi,
As a novice to shell script, can someone pls. let me know as to how do I find the count of number of occurence of a particular character in a record.
To be more specific, if I have 100 records in my file, I have to take 1 record at a time, in a loop, and find the count of number of occurence of double quotes (") in that record.
Any help would be sincerely appreciated.
Shyam.
|
***********************************
INPUT="\"" ;
TOTAL=0;
char="";
for WORD in `cat $1 `
do
LOOPCOUNT=1 ;
char=` echo $WORD | cut -c $LOOPCOUNT-1 ` ;
while [ "$char" ]
do
if [ "$char" = "$INPUT" ]; then
TOTAL=` expr $TOTAL + 1 ` ;
fi ;
LOOPCOUNT=` expr $LOOPCOUNT + 1 ` ;
char=` echo $WORD | cut -c $LOOPCOUNT-$LOOPCOUNT ` ;
done ;
done ;
print "THE TOTAL COUNT IS : $TOTAL " ;
***********************************
Hope that the above will work for you,
All you need to do is embed this in ur script or call it separately after putting each record in a file.
Hanuman.