The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how can i extract text section via grep meny UNIX for Dummies Questions & Answers 8 07-03-2009 03:58 AM
Perl script to search and extract using wildcards. CammyD Shell Programming and Scripting 3 04-20-2009 03:17 PM
Search for string in a file and extract another string to a variable daikeyang Shell Programming and Scripting 6 03-20-2009 08:45 PM
using sed to conditionally extract stanzas of a file based on a search string aitayemi Shell Programming and Scripting 0 11-25-2008 06:16 PM
New Section kapilv Post Here to Contact Site Administrators and Moderators 3 10-31-2001 09:57 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-25-2009
haphazard haphazard is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 2
Search and extract by section from configuration

Hi,

I understand either AWK or SED can do this, but I not sure how to extract the following configuration in section. Meaning when I need to find code with " ip helper-address 192.168.11.2" , it would start from "interface Serial0/0" and "interface FastEthernet0/1". Only displaying both section by chunk.

If anyone can point me in the right direction , it would be great. Thanks.

Sample configuration
===========================================
!
interface FastEthernet0/0
description R2 Fa0/0
ip address 192.168.1.1 255.255.255.0
duplex auto
speed auto
!
interface Serial0/0
description R2 Se0/0
bandwidth 2000
ip address 192.168.11.1 255.255.255.0
ip helper-address 192.168.11.2
encapsulation ppp
!
interface FastEthernet0/1
description LAN interface
ip address 10.1.1.1 255.255.255.0
ip helper-address 192.168.11.2
duplex auto
speed 10
!
interface Serial0/1
no ip address
shutdown
!
router eigrp 1
network 10.1.1.0 0.0.0.255
network 192.168.1.0
network 192.168.11.0
no auto-summary
!
===========================================

Expected results :
===========================================
interface Serial0/0
description R2 Se0/0
bandwidth 2000
ip address 192.168.11.1 255.255.255.0
ip helper-address 192.168.11.2
encapsulation ppp
!
interface FastEthernet0/1
description LAN interface
ip address 10.1.1.1 255.255.255.0
ip helper-address 192.168.11.2
duplex auto
speed 10
!
  #2 (permalink)  
Old 08-25-2009
agn agn is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 172

Code:
$ awk 'BEGIN { RS = ORS = "!"; FS="\n"; } /ip helper-address 192\.168\.11\.2/ { print $0 }' filename

  #3 (permalink)  
Old 08-25-2009
haphazard haphazard is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 2
Thanks a million agn, this would save me hours of manually looking/ctrl+F through the configurations

this forum rocks and so does AWK

Last edited by haphazard; 08-25-2009 at 04:29 AM.. Reason: typo
Reply

Bookmarks

Tags
awk, sed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0