#!/usr/bin/awk -f BEGIN { dev = "" FS = "[: ]+" while("ip addr show primary"|getline) { if (match($0, "^[1-9]+:[ \t]+[^ \t@:]+")) { dev = $2 sub("@.*","",dev) } else if ("inet" == $2) { if ( "" == ip[dev]) { ip[dev] = $3 } else if ( dev == $(NF-1)) { dev = $(NF-1)":"$NF sub("@.*","",dev) ip[dev] = $3 while ( "" == ip[dev] ) ip[dev] = $3 if ( dev == "eth2:0" ) print ip[dev] if ( "" == ip[dev] ) print "ACHTUNG: ip[dev] missing" if ( "" == $3 ) print "ACHTUNG2: \$3 missing too" } } } }