Skip to content

Instantly share code, notes, and snippets.

@OwenChia
Last active April 22, 2017 12:58
Show Gist options
  • Save OwenChia/478434ce0bf355c4f4cc957822dd60a4 to your computer and use it in GitHub Desktop.
Save OwenChia/478434ce0bf355c4f4cc957822dd60a4 to your computer and use it in GitHub Desktop.
getip.sed
#! /bin/sed -nf
# Usage:
# ip addr | sed -nf getip.sed | column -t
/^[[:digit:]]/ {
: begin
s/^[[:digit:]]\+: \([[:graph:]]\+\).*/\1/
h
: loop
n
/^[[:digit:]]/b begin
s/.*inet \([[:digit:]\.\/]\+\).*/\1/
T loop
H
x
s/\n/ /
p
}
@OwenChia
Copy link
Author

How it works:

Pattern Space Hold Space
interface ...

h

Pattern Space Hold Space
interface interface

n

Pattern Space Hold Space
address interface

H

Pattern Space Hold Space
address interface\naddress

x

Pattern Space Hold Space
interface\naddress address

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment