sed script question

Kim Holburn kim.holburn at anu.edu.au
Wed Feb 26 22:50:06 EST 2003


I have a sed script that takes this output:

test:/etc# ip link
1: lo: <LOOPBACK,UP> mtu 16436 qdisc noqueue 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 100
    link/ether 00:10:18:01:bd:d5 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 100
    link/ether 00:10:18:01:bd:d0 brd ff:ff:ff:ff:ff:ff
4: ext1: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 100
    link/ether 00:06:5b:f3:09:5e brd ff:ff:ff:ff:ff:ff
5: eth3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 100
    link/ether 00:06:5b:f3:09:5f brd ff:ff:ff:ff:ff:ff
6: sit0 at NONE: <NOARP> mtu 1480 qdisc noop 
    link/sit 0.0.0.0 brd 0.0.0.0

and turns it into this:
test:/etc# ./nics.sh 
eth0:  00:10:18:01:bd:d5 
eth1:  00:10:18:01:bd:d0 
ext1:  00:06:5b:f3:09:5e 
eth3:  00:06:5b:f3:09:5f 

here it is:
test:/etc# more nics.sh 
#!/bin/sh

ip link|sed -e :a -e '$!N;s/\n / /;ta' -e 'P;D' | \
  sed -e '/link\/ether/!d' \
      -e 's/^[0-9][0-9]*: //' \
      -e 's#<.*link/ether##' \
      -e 's/brd.*$//'


Can anyone show me how to add the commands for the 2 instances of sed so I only have to invoke it once?  I'm not really sure how the first sed command works although I knwo what it does but just putting all the commands together on one sed doesn't seem to work!

Kim
-- 
--
Kim Holburn  
Network Consultant - Telecommunications Engineering
Research School of Information Sciences and Engineering
Australian National University - Ph: +61 2 61258620 M: +61 0417820641
Email: kim.holburn at anu.edu.au  - PGP Public Key on request

Life is complex - It has real and imaginary parts.
     Andrea Leistra (rec.arts.sf.written.Robert-jordan)


More information about the linux mailing list