If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Help required. Simple Script.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-13-03, 23:58
Mike10 Mike10 is offline
Registered User
 
Join Date: Oct 2003
Posts: 7
Help required. Simple Script.

Greetings,

I want to know what the simplist way to check contents of a text file is.

Ie. I have a text file called datatest with the following in it:
Mike
Joe
Blair

I want a script that will check the contents of that file and compare it with a variable I have created in the script. If there is a match for all then it will echo back 'Success'. If not, then it will echo back which were not found.

#!/usr/bin/ksh
count=0
check="Mike Joe Blair"
for namex in $check
do
if grep $namex datatest > /dev/null; then
count='expr $count + 1
echo "$namex found"
fi
done
if [ $count==3 ]; then
echo "Success"
else
echo "Did not find all matches"
fi


I am new at this so sorry if it looks silly. I think the $count=3 is wrong (I want to check the 3 names and if all 3 match the text file datatest then success). Any suggestions? The count works but I can't get the $count==3 part to recognize the value properly. Even though the count is 3, it doesn't give me a 'success' Thanks.
Reply With Quote
  #2 (permalink)  
Old 10-14-03, 10:28
skd skd is offline
Registered User
 
Join Date: Sep 2003
Posts: 71
not sure but can Try replacing $count == 3 by $count -eq 3
Reply With Quote
  #3 (permalink)  
Old 10-14-03, 13:23
Mike10 Mike10 is offline
Registered User
 
Join Date: Oct 2003
Posts: 7
Thanks

Thanks..that worked. I though I already tried that before....oh well, I guess it was a long time and I missed it.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On