samedi 7 septembre 2019

What is the correct syntax for nesting if-statements in awk?

I'm writing a awk command and I would like to nest if-statements using the conditional block form:

condition{actions}

instead of the one that uses the if keyword:

if(condition){actions}

This because I'm trying to use as few characters as possible.

Using the if keyword it works:

awk '{system("date +%s%N")}'|awk '{b++;}b>1{if(b>4)e=b-5;t[b]=$1;r=int(3E11/(t[b]-t[++e]));print r,"bpm"}'

but when I try to do with the other way:

awk '{system("date +%s%N")}'|awk '{b++;}b>1{b>4{e=b-5;}t[b]=$1;r=int(3E11/(t[b]-t[++e]));print r,"bpm"}'

I get a syntax error:

awk: lin. de com.:1: {b++;}b>1{b>4{e=b-5;}t[b]=$1;r=int(3E11/(t[b]-t[++e]));print r,"bpm"}

awk: lin. de com.:1:(......................)^ syntax error

What would be the correct syntax?

Aucun commentaire:

Enregistrer un commentaire