troubleshooting Question

use an input file to replace

Avatar of richsark
richsarkFlag for United States of America asked on
PerlShell Scripting
14 Comments1 Solution293 ViewsLast Modified:
Hello Folks,

I have this perl script

#!/usr/bin/perl
use File::Find;
open F,shift or die $!;
my %ip=map/(\S+)\s+(\S+)/,<F>;
close F;
find sub{
  if( -f ){
     local @ARGV=($_);
     local $^I="";
     while( <> ){
           !/#/ && s/(\w+)domain-name-servers/$ip{$1}/g;
           print;
     }
  }
},@ARGV

Its not working and need help to make it work.

I have an input file called "rich-input.txt"

In the fie I have lines that look like so

addnsr1pri.fs.rich.us          116.7.3.101
addnsr1sec.fs.rich.us         116.2.100.78
addnsr2pri.fs.rich.us          116.2.220.140
addnsr2sec.fs.rich.us         116.3.68.105

In my PWD

I have many folders like R1, R2, W2 etc...

What I am trying to do is have this script look in every directory find the line that has

option domain-name-servers addnsr1pri.fs.rich.us., addnsr1sec.fs.rich.us

and change to an IP like so:

option domain-name-servers 116.7.3.101, 116.2.100.78

Also skipping any # that may exist

The script runs somewhat but it changes stuff I dont want i.e option domain-name

Plus is screws up my input file with all IP's


I run it from (( using cygwin):

~/US-Rich/Service/Data/NEW-JAN-21/RICH_20120120_RICH_data/dhcp

or in windows:

C:\US-Rich-Service\Data\NEW-JAN-\RICH_20120120_RICH_data\dhcp

using

change.pl rich-input.txt *

Thanks for your help in advanced
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 14 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros