awk for streaming data - if/then

Hello,

I've written an awk one-liner to parse a stream of real-time data. I invoke a program that gives me output from which I extract a few columns, perform some simple calculations, and then stream that data into a portal using an http string. It's tricky because I have to run it every second to parse the data I need, but it works.

My question is about adding in an if/then statement. I need to check if the output of Ntripclient2.py actually has the data I need. If it doesn't I need to move on, not parse it, and run the awk one-liner again until I actually get the data I need. The problem is I end up parsing an error message, and it bogs down my portal.

I need to check NR==13, if($5==0) skip the parse step and keep going. Does that make sense?

Here's the one-liner:

Ntripclient2.py --user $1 $2.unavco.org $3 $4_RTX | awk -F, 'NR>7 {cmd="curl \42http://'$5'.chordsrt.com/measurements/url_create?instrument_id='$6'&lat="substr($5,1,2)+(substr($5,3)/60)"&lon="substr($7,1,3)+(substr($7,4)/60)"&height="substr($12,4)"&at=""20"substr($4,5,2)"-"substr($4,1,2)"-"substr($4,3,2)"T"substr($3,1,2)":"substr($3,3,2)":"substr($3,5,2)"\42";system(cmd)}'

You can use a next statement:-

NR > 7 { 
	if ( ( NR == 13) || ( $5 == 0 ) )
		next
	else
		<parsing code here>
}
2 Likes

:slight_smile: Thanks!