Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to know if have some sed, grep or awk regex to parse Cisco interface section and exclude if interface is down (shutdown), like example below.


interface FastEthernet0/1
 ip address
interface FastEthernet0/2
 ip address

I'm using sed regex below to parse interface section:

sed -n -e '/^interface/,/^!/p' file.txt

But the regex above, parse all interface and not exclude interface down.

share|improve this question
FYI, you asked for shell tools; however, ciscoconfparse is a python module which specializes in handling these kind of tasks. If you do a lot of this, it may be worth your while to consider using a library which is built for parsing cisco configs. – Mike Pennington Feb 8 '14 at 19:29


With GNU awk or mawk you could do it like this:

awk -v RS='!\n' '!/shutdown/'


interface FastEthernet0/1
 ip address

You could make the match more precise if you only look for shutdown in the third line:

awk -v RS='!\n' -v FS='\n +' '$3 !~ /shutdown/'


You can of course also use sed, but it is more complicated.

One approach is the one you've started with, but collect the whole record in hold space before printing anything. This works with GNU sed:

sed -n '/^interface/,/^!/ H; 1b; /^!/ { z; x; s/^\n//g; /shutdown/!p }'
share|improve this answer
Thank you very much. It's work. – user32634 Feb 20 '13 at 11:55
@user32634: I'm glad it helped you. The way to say thanks around here is by up-voting useful answers and accepting the most useful answer. – Thor Feb 20 '13 at 12:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.