Search and extract by section from configuration


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search and extract by section from configuration
# 1  
Old 08-25-2009
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  
Old 08-25-2009
Code:
$ awk 'BEGIN { RS = ORS = "!"; FS="\n"; } /ip helper-address 192\.168\.11\.2/ { print $0 }' filename

# 3  
Old 08-25-2009
Thanks a million agn, this would save me hours of manually looking/ctrl+F through the configurations

this forum rocks and so does AWK Smilie

Last edited by haphazard; 08-25-2009 at 05:29 AM.. Reason: typo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying section of file based on search criteria

Hi Guru's, I am new to unix scripting. I have a huge file with user details in it(file2) and I have another file with a list of users(file1). Script has to search a user from file1 and get all the associated lines from file2. Example: fiel1: cn=abc cn=DEF cn=xyx File 2: dn:... (10 Replies)
Discussion started by: Samingla
10 Replies

2. Shell Programming and Scripting

Extract record from file based on section.

input file output file (1 Reply)
Discussion started by: lathigara
1 Replies

3. Shell Programming and Scripting

Search for a pattern,extract value(s) from next line, extract lines having those extracted value(s)

I have hundreds of files to process. In each file I need to look for a pattern then extract value(s) from next line and then search for value(s) selected from point (2) in the same file at a specific position. HEADER ELECTRON TRANSPORT 18-MAR-98 1A7V TITLE CYTOCHROME... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

4. Shell Programming and Scripting

Deleting a section based on search from other file

Hi Everyone, I need some help to accomplish the below. help is highly appriciated. I have a 45 mb file with ldap entries. Each user entry is separated by a string # entry-id: 1 and so on. Some of the entries has a string xyz: true. I want to delete the section if the user section has xyz: true... (6 Replies)
Discussion started by: Samingla
6 Replies

5. Shell Programming and Scripting

Parse configuration file & add line in particular section

Greetings, I recently built a replicated DRBD, Heartbeat, & iSCSI Target Initiator storage server on Ubuntu 10.04 to offer shared storage to server Vmware ESX and Microsoft Clusters. Everything works flawlessly, however I wanted to make a script to create, remove, grow volumes to offer ESX... (6 Replies)
Discussion started by: Aeudian
6 Replies

6. Shell Programming and Scripting

Format output from the file to extract "date" section

Hello Team , I have to extract date section from the below file output. The output of the file is as shown below. I have to extract the "" this section from the above output of the file. can anyone please let me know how can we acheive this? (4 Replies)
Discussion started by: coolguyamy
4 Replies

7. Shell Programming and Scripting

Extract section of file based on word in section

I have a list of Servers in no particular order as follows: virtualMachines="IIBSBS IIBVICDMS01 IIBVICMA01"And I am generating some output from a pre-existing script that gives me the following (this is a sample output selection). 9/17/2010 8:00:05 PM: Normal backup using VDRBACKUPS... (2 Replies)
Discussion started by: jelloir
2 Replies

8. Shell Programming and Scripting

Parse Multi-Section Configuration File

Hello all, Sample configuration file: username = root password = admin IpAddress = 192.168.2.90 HttpCommand = /getfile?hello.jpg Username = root2 Password = admin2 Passive = no Host = 192.168.1.100 Path = /uploads Username = root3 Password = adming Passive = no Host =... (10 Replies)
Discussion started by: LAVco
10 Replies

9. Shell Programming and Scripting

Search and Remove No data Section

Hello, I have written a script that removes duplicates within a file and places them in another report. File: ABC1 012345 header ABC2 7890-000 ABC3 012345 Content Header ABC5 593.0000 587.4800 ABC5 593.5000 587.6580 ABC5 593.5000 587.6580 ABC1 67890 header ABC2 1234-0001 ABC3... (2 Replies)
Discussion started by: petersf
2 Replies

10. UNIX for Dummies Questions & Answers

how can i extract text section via grep

hi, i have a very long text file. i need to extract with grep command a certain part. for example text file include 1ooo rows: 1.... 2... 3... . . . 1000 i want to view with grep only rows 50-100. any ideas will be appreciated thanks... (8 Replies)
Discussion started by: meny
8 Replies
Login or Register to Ask a Question