Skip to main content
added 7 characters in body
Source Link
Cbhihe
  • 2.9k
  • 4
  • 24
  • 33

An alternative in case you have such patterned occurrence happening once or more than once in your file:

$ awk '/^Energy initial, next-to-last, final =/ {a[NR]=1} 
       {if(NR >= 3 && a[NR-2] == a[NR] && a[NR] == 1) {toprint=1; next}}
       {if (toprint) {print $3; toprint=0}}' infile

No matter, Hauke's solution is far less ugly.

An alternative in case you have such patterned occurrence happening once or more than once in your file:

$ awk '/^Energy initial, next-to-last, final =/ {a[NR]=1} 
       {if(NR >= 3 && a[NR-2] == a[NR] && a[NR] == 1) {toprint=1; next}}
       {if (toprint) {print $3; toprint=0}}'

No matter, Hauke's solution is far less ugly.

An alternative in case you have such patterned occurrence happening once or more than once in your file:

$ awk '/^Energy initial, next-to-last, final =/ {a[NR]=1} 
       {if(NR >= 3 && a[NR-2] == a[NR] && a[NR] == 1) {toprint=1; next}}
       {if (toprint) {print $3; toprint=0}}' infile

No matter, Hauke's solution is far less ugly.

Source Link
Cbhihe
  • 2.9k
  • 4
  • 24
  • 33

An alternative in case you have such patterned occurrence happening once or more than once in your file:

$ awk '/^Energy initial, next-to-last, final =/ {a[NR]=1} 
       {if(NR >= 3 && a[NR-2] == a[NR] && a[NR] == 1) {toprint=1; next}}
       {if (toprint) {print $3; toprint=0}}'

No matter, Hauke's solution is far less ugly.