I am a beginner in using Linux, I have an input file with content like:
00.11.11.11.11.11
177.22.22.22
one line of Ethernet address and one line of IP address,
how can I convert this file to:
IP: 177.22.22.22 MAC: 00.11.11.11.11.11
I think awk would do it, but I don’t know how. Any ideas?
Thanks!
It could be done with ‘sed’, too, but since you ask for ‘awk’, ‘awk’ it shall be.
(Previous version:
Not so good because of the written out repeat, instead of counted repeat.)
The first line matches MAC addresses and saves the most recent in variable mac. The second matches IP (IPv4) addresses and prints the current MAC address and IP address.
If you have stray leading or trailing blanks, or other stray characters, you need to make the regexes appropriately more complicated.