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 ...
- 12-20-2007 #1Just Joined!
- Join Date
- Apr 2007
- Posts
- 3
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.
- 12-20-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Try this:
RegardsCode:awk' $3=="CH:RA"{f=1;next} $3=="CH:RV" && f{print substr($5,4,3} f=0 ' file
- 12-20-2007 #3Just Joined!
- Join Date
- Apr 2007
- Posts
- 3
I tried this and get an error:
Bad name after awk'
- 12-20-2007 #4Just 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
- 12-21-2007 #5Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
There must be a space between awk and the quote:
RegardsCode:awk ' $3=="CH:RA"{f=1;next} $3=="CH:RV" && f{print substr($5,4,3} f=0 ' file


Reply With Quote