Would appreciate to know about the special char or wildcard in the following command:
/sbin/ifconfig eth0 | awk -F ' *|:' '/inet addr/{print $4}'
What does the code below mean?
awk -F ' *|:' '
awkshell-scripting
Would appreciate to know about the special char or wildcard in the following command:
/sbin/ifconfig eth0 | awk -F ' *|:' '/inet addr/{print $4}'
What does the code below mean?
awk -F ' *|:' '
Best Answer
The -F flag (for awk) means to use the following extended regular expression as a Field separator Which means it treats any of the characters between the single quotes here:
' *|:'
as delimiters.Awk will then print the 4th field that has a match with
inet addr
.For example: if this were the output for
ifconfig eth0
:It should print out
To break down the regular expression:
the
Means any number of spaces, and the remaining characters have no special meaning, so either of them can be a delimiter. The
*
itself is not a delimiter, it just means any number of the preceding character, a space.