Skip to content

Instantly share code, notes, and snippets.

@Raven24
Created July 29, 2012 22:25
Show Gist options
  • Save Raven24/3202188 to your computer and use it in GitHub Desktop.
Save Raven24/3202188 to your computer and use it in GitHub Desktop.
IP address, MAC address and device name with sed
#!/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