It works. Thanks. i am trying to understand this oneliner. does it mean the match function searches for the match and holds something like pointer to the line thats matched and whatever processing is done would start from the matched line onwards ?
ifconfig -a |awk -v ip=1.1.1.1 '
match( $0, ip ) { # if the ip address is on this line
getline; # get the next line from the input file
print $2; # print the second field
exit; # stop processing input
}'
Remember that awk reads each line of the input file (output from ifconfig in this case) and applys the condition to the line. In this case the condition is the match command which returns true when the desired string is somewhere in the input line.
It could also be written like this, which I think is a bit easier to understand, but less clear as a one liner:
ifconfig -a |awk -v ip=1.1.1.1 '
{
if( match( $0, ip ) )
{
getline;
print $2;
exit;
}
}'