Created
July 29, 2012 22:25
-
-
Save Raven24/3202188 to your computer and use it in GitHub Desktop.
IP address, MAC address and device name with sed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ifconfig -a | grep -A 3 ^eth | sed -n -e ' | |
# add first line to hold space | |
1h | |
# add all other lines to hold space | |
1!H | |
${ | |
# write hold space to pattern space | |
g | |
# regex replacement: "device: ip address - mac address" | |
s/^\(eth[0-9]\).\+\?\(inet \([0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\{3\}\)\).\+\?\(ether \([0-9a-f]\{2\}\(:[0-9a-f]\{2\}\)\{5\}\)\).\+/\1:\t\3\t-\t\6/ | |
# output replacement | |
p | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment