Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, 1) I need to search a field value to check for exact 0. If the number is 0, it should throw error. The line to be searched looks like ...
  1. #1
    Just Joined!
    Join Date
    Jul 2010
    Posts
    16

    grep for exact number 0

    Hi,



    1) I need to search a field value to check for exact 0. If the number is 0, it should throw error.

    The line to be searched looks like as below.

    "Output Rows [1], Affected Rows [1], Applied Rows [1], Rejected Rows [0]"

    Here I have to search whether the affected rows is 0. But the code below picks up other values also (lie 10, 20.. etc). How do we write to get an exact match for 0?

    Code:
    affected=`echo ${line} | cut -f6 -d" "  `
    
     affectedcount='echo ${affected} |grep 0 `
    2) Also, I need to check whether the rejected rows > 0

    Code:
    rejected=`echo  ${line} | cut -f12 -d" " `
    rejectedcount='echo  {rejected}  |grep [1-9]`

    3)Can we combine these two statements in a better way to get the desired results?

    Thanks
    Maya

  2. #2
    Linux Newbie theNbomr's Avatar
    Join Date
    May 2007
    Location
    BC Canada
    Posts
    150
    You can use grep to extract only the numeric characters :

    Code:
    affectedcount=$(echo ${line} | cut -f6 -d" " | grep -o '[0-9]\+')
    --- rod.
    Stuff happens. Then stays happened.

  3. #3
    Just Joined!
    Join Date
    Jul 2010
    Posts
    53
    awk -F, '$2==0{print;}'

Posting Permissions

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