Search a particular config in many files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search a particular config in many files
# 1  
Old 11-23-2015
Blade Search a particular config in many files

Hi,
Having trouble in our network we would like to implement a second "ip-helper" (to have DHCP redondancy) to do so we have to take all the network elements config (switches and routers) , finds where the particular config is and add a second line. To do so we need to have a list where this ip-helper line is. but we need also to keep the line where "interface ..." is

basically I need to make a script uising awk or other to do the following :

1. open the files one by one and find the "ip-helper ..."

file1
Code:
  ... 
  interface xxxxxx
  ip-helper 10.10.10.1
  ip address 192.168.4.4 255.255.255.0
  ...

or 

interface xxxxxx
  ip address 192.168.4.4 255.255.255.0
  ip-helper 10.10.10.1

file2
Code:
 ...
  interface vlan3
  ip address 192.168.4.4 255.255.255.0
  ip-helper 10.10.10.1
...


then I want to have as a result only one file with

result.txt :
Code:
filename1(where the text was found)
interface xxxxxx
  ip-helper 10.10.10.1
filename2(where the text was found)
interface xxxxxx
  ip-helper 10.10.10.1
...


complex no ? Smilie
Any help would be appreciate. I didn't do Scripting since years now and I have just got new job that I would like to keep.
Thanks to every contributors.

Moderator's Comments:
Mod Comment please use code tags for your code and data

Last edited by vbe; 11-23-2015 at 05:35 AM.. Reason: forgot some part
# 2  
Old 11-23-2015
No. Try
Code:
awk '/interface/ {IF = $0} /ip-helper/ {print FILENAME; print IF; print}' file1 file2
file1
  interface xxxxxx
  ip-helper 10.10.10.1
file2
  interface vlan3
  ip-helper 10.10.10.1

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

(VS 2008) New build config looking files from other folder build config

Hi Team, My new build configuration always looking for the files from the build where i copied from. please help me to resolve this. I am using Visual studio 2008.It has Qt 4.8. plugins,qml,C++ development I created new debug_new build configuration with additional preprocessor from the... (1 Reply)
Discussion started by: SA_Palani
1 Replies

2. Shell Programming and Scripting

What's the best way to read config files?

(copied directly from my other thread about something else) At the moment, I just use... cat config_file|grep var_name|cut -d'=' -f2 ... which is fine for what I've been doing, but I'm not sure what to do when there are a variable number of entries and I want it go through them like a... (7 Replies)
Discussion started by: ninjaaron
7 Replies

3. SuSE

Search all files based on first and in all listed files search the second patterns

Hello Linux Masters, I am not a linux expert therefore i need help from linux gurus. Well i have a requirement where i need to search all files based on first patterns and after seraching all files then serach second pattern in all files which i have extracted based on first pattern.... (1 Reply)
Discussion started by: Black-Linux
1 Replies

4. Shell Programming and Scripting

using perl config files

Hi, I have 2 perl SubRoutines (sub 1 and sub 2). I created two perl modules for these (Sub1.pm and Sub2.pm). How can I include these in a config file (say Config.cfg) and call the config file in my main script Rename.pl to use the 2 subroutines? Right now here are the content of Config.cfg... (1 Reply)
Discussion started by: CCFP
1 Replies

5. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

6. Shell Programming and Scripting

parsing config file to create new config files

Hi, I want to use a config file as the base file and parse over the values of country and city parameters in the config file and generate separate config files as explained below. I will be using the config file as mentioned below: (config.txt) country:a,b city:1,2 type:b1... (1 Reply)
Discussion started by: clazzic
1 Replies

7. HP-UX

Config Files

Does anyone have a list of key config files and the respective paths for HP-UX? Or does anyone know where I can get a list similar to this? Thanks, TOdd (0 Replies)
Discussion started by: toddjameslane
0 Replies

8. UNIX for Dummies Questions & Answers

Apache Config Files

Currently our Apache log files are huge, I want to put say a month's time limit on this, then when it hits the end of the month I would like it to start over writing. Does anyone know where the config file is for this and what its called? I also want to do exactly the same on wtmp config (who... (1 Reply)
Discussion started by: Webwitch
1 Replies

9. UNIX for Dummies Questions & Answers

new LAN, where are the config files?

We just moved to a new office so few things changed on our LAN. I am on Solaris and trying to find the files that hold the configuration for connecting to the servers. I changed the IP addresses to reflect the new addresses but still I get this error: “unknown sendmail : unable to qualify my own... (3 Replies)
Discussion started by: softarch
3 Replies
Login or Register to Ask a Question