Need urgent help

Hi geeks,
I'm trying to write a below script, but it throws an error, please check and correct me.

#!/bin/bash
#The below script will extract the string error1 error2 and error3 and also it will count and list the occurrence
count1='grep -i "error1" test.txt | wc -l'
count2='grep -i "error2" test.txt | wc -l'
count3='grep -i "error3" test.txt | wc -l'
while read line
do
echo $count1
echo $count2
echo $count3
done <test.txt 
/usr/sbin/sendmail -f "eai-alert" naren.ballurkar@XYZ.com<<EOF
To: naren.ballurkar@XYZ.com
Subject: Test Sub

Count for error1: $count1
Count for error1: $count2
Count for error1: $count3

---------------------------------------------------------
EOF

Error is as below

sh script1.sh
script1.sh: line 11: syntax error near unexpected token `done'
'cript1.sh: line 11: `done <test.txt

is there a file called "test.txt"???

I guess you should try the absolute path for your file.

First, you need to get rid of the carriage return characters in your script.

Second, delete:

count1='grep -i "error1" test.txt | wc -l'
count2='grep -i "error2" test.txt | wc -l'
count3='grep -i "error3" test.txt | wc -l'
while read line
do
echo $count1
echo $count2
echo $count3
done <test.txt 

and then try changing:

Count for error1: $count1
Count for error1: $count2
Count for error1: $count3

to:

Count for error1: $(grep -Fic error1 test.txt)
Count for error2: $(grep -Fic error2 test.txt)
Count for error3: $(grep -Fic error3 test.txt)

Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.

Thank you.

The UNIX and Linux Forums