Find the answer to your Linux question:
Results 1 to 5 of 5
I want to clarify that this is not homework. It is one of my many things I have to do at work and I was trying to save myself some ...
  1. #1
    Just Joined!
    Join Date
    Apr 2007
    Posts
    3

    Post RE: Script to read file and locate specific lines and do some math with the numbers.

    I want to clarify that this is not homework. It is one of my many things I have to do at work and I was trying to save myself some time.

    21126.43870 HEART_PARAMETER_CHANGE_EVENT ParamID:111 ParamVal:59(0x3B)
    21126.44470 HEART_BEAT_EVENT CH:RV Cause:Conducted LT:857 WFIndex:7 PPAMP:100
    21126.44670 HEART_PARAMETER_CHANGE_EVENT ParamID:112 ParamVal:59(0x3B)
    HEART_SCENARIO_STRING_DISPLAY Strlen:31 String:4.5.7.1 TC1.0: AV SEARCH FEATUR
    21127.31369 HEART_BEAT_EVENT CH:RA Cause:Normal LT:869 WFIndex:7 PPAMP:100
    21127.41469 HEART_BEAT_EVENT CH:RV Cause:Conducted LT:970 WFIndex:7 PPAMP:100

    What I need to do is to find the lines with RA in followed by RV and subtract the value of LT on the RV line from the value of LT on the RA line and write the value to another text file.

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Try this:

    Code:
    awk'
    $3=="CH:RA"{f=1;next}
    $3=="CH:RV" && f{print substr($5,4,3}
    f=0
    ' file
    Regards

  3. #3
    Just Joined!
    Join Date
    Apr 2007
    Posts
    3
    I tried this and get an error:

    Bad name after awk'

  4. #4
    Just Joined!
    Join Date
    Nov 2004
    Posts
    18
    I guess what Franklin52 meant was:
    Code:
    awk ' $3 == "CH:RA" { f = 1; ra = substr($5,4,3); next }
          $3 == "CH:RV" && f { f = 0; rv = substr($5,4,3); print rv-ra } '
    data.txt > result.txt

  5. #5
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    There must be a space between awk and the quote:

    Code:
    awk '
    $3=="CH:RA"{f=1;next}
    $3=="CH:RV" && f{print substr($5,4,3}
    f=0
    ' file
    Regards

Posting Permissions

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