Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Posts
    7

    Unanswered: 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.

  2. #2
    Join Date
    Sep 2003
    Posts
    71
    not sure but can Try replacing $count == 3 by $count -eq 3

  3. #3
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •