I created the following awk command in order to print only the line that match the host and the ETH parameters
my problem is that I don’t know which eth1-8 is the real argument
How to print the line from the file by awk if ETH could be eth0 or eth1 or eth2 ….etc until eth8
HOSTNAME=linux1
LAN=eth0|eth1|eth2|eth3|eth4|eth5|eth6|eth7|eth8
awk -v host=$HOSTNAME -v ETH=$LAN '$2 == host && $3 == ETH' file
more file
192.17.200.10 linux1 eth0
192.17.200.10 linux1 eth1
192.17.200.11 linux2 eth2
192.17.200.12 linux3 eth3
192.17.200.13 linux4 eth4
192.17.200.14 linux5 eth5
192.17.200.15 linux6 eth6
192.17.200.16 linux7 eth7
192.17.200.17 linux8 eth8
Use a regular expression to specify the possible matches, e.g.:
In terms of the shell variable, you’ll want something like: