Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Posts
    143

    Unanswered: grep for count of a word

    In a unix shell script(say do.ksh), I want to read a file called load_errors.log and count the word ORA- for the number of occurances.
    If the occurance is more than 50, then I would like the unix shell script to exit with a message "ORA- found more than 50 times"

    How can this be done ? Thanks

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    The following script assume that there is no more than one error per line:

    Code:
    if (( $(grep -c 'ORA-' ) > 50 ))
    then
       echo "ORA- found more than 50 times"
    fi
    Jean-Pierre.

  3. #3
    Join Date
    Feb 2004
    Posts
    143

    will this be fine

    Thank you. But the script that I want to include these lines is supposed to grep in another file for those words.
    How do I specify the other file usage ?


    Will this work:

    if (( $(grep -c 'ORA-' load_errors.log ) > 50 ))
    then
    echo "ORA- found more than 50 times"
    fi

  4. #4
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    This will work.
    I have tested my script with stdin and forget to add the file name in my post.
    Jean-Pierre.

Posting Permissions

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