This should print the previous name value when target is 'offline' and state is 'online':
awk -F = '
/^NAME/ { n = $2; next }
/^TARGET/ { t = $2; next; }
/^STATE/ {
if( t == "OFFLINE" && $2 == "ONLINE" )
print n;
}
' file.txt
It makes the assumptions that NAME, STATE, and TARGET are always the first tokens on each record with no leading whitespace and that there isn't more than one name=value pair per line.
but with one exeception i.e ( TARGET=OFFLINE and STATE=ONLINE)
It makes the assumptions that NAME, STATE, and TARGET are always the first tokens on each record with no leading whitespace and that there isn't more than one name=value pair per line.
Your assumption is true.
---------- Post updated at 10:27 PM ---------- Previous update was at 10:12 PM ----------
Can anyone help-me out ? I am basically sql developer but learning the UNIX now.