DBAsupport.com Forums - Powered by vBulletin
Results 1 to 6 of 6

Thread: Korn Shell question

  1. #1
    Join Date
    Mar 2001
    Posts
    287
    The following code block is C shell and is working. Can some body "translate" it to Korn shell? Thank you!

    if { ( cat ck_Alert.log|grep "Mi" >& /dev/null ) } then
    echo "Find the pattern"
    endif

  2. #2
    Join Date
    Mar 2001
    Posts
    314
    dummy=`grep -q "Mi" ck_Alert.log`
    if [ $? -eq 0 ] ; then
    echo "Find the pattern"
    fi

    -amar

  3. #3
    Join Date
    Mar 2001
    Posts
    287
    amar,

    You are so kind to provide this solution. However, I need to do the similar tests 10 times in my major script. I prefer to test the exit status in the "if condition" instead of testing seperately. I can do this on C shell. I just wonder if Korn shell can do the same thing. (I mean, do the cat-grep-test exit status in the same line.)

    Thank you!

  4. #4
    Join Date
    Oct 2000
    Location
    Saskatoon, SK, Canada
    Posts
    3,925
    if [[ -n `cat ck_Alert.log|grep "Mi"` ]]
    then
    echo "Found the pattern"
    fi




    Sam
    Thanx
    Sam



    Life is a journey, not a destination!


  5. #5
    Join Date
    Mar 2001
    Posts
    314
    or, if you want to stick to "grep"..........

    if [ `grep "Mi" ck_Alert.log | wc -l` -ne 0 ] ; then
    echo found
    fi

    -amar

  6. #6
    Join Date
    Mar 2001
    Posts
    287
    Thank you!!!


Posting Permissions

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


Click Here to Expand Forum to Full Width