A
Ajay
Hi All,
I've to search and replace the value of strings from a file.
The first string "giccip" can have multiple instances but i have to replace it's
value from the first instance only.
In the file "gicc" appear as follows, and it appears in the last of that line:
giccip=0x0a0600b0
The second string "STC1NSAP" has only one instance and i have to replace it's
value. It's on its own line
STC1NSAP=32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32
Here is my perl script
I'm on solaris
#!/usr/local/bin/perl -w
###########################################################
## This script changes the giccip address
## and STC1NSAP addresses in odd_persist file
###########################################################
#use warning;
#use strict;
my $FALSE = 0;
my $TRUE = 1;
my $FOUND = $FALSE;
my $odd11dir = "odd11";
my $odd11file = "odd11/odd_persist";
my $slot11ip = "0x0a0600b0";
my $STC1NSAP12 = "32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32";
### check if the script is run from the correct directory
### check if odd_persist files exist in odd1 & odd12 dirs
if (! -e $odd11dir)
{
die("directory $odd11dir not found \n");
}
if ( ! -e $odd11file )
{
die("$odd11file file doesn't exist \n");
}
### open odd11/persist file and replace first giccip address with correct value
### and replace STC1NSAP Address
open(ODD11, $odd11file) || die("can't open $odd11file : $!\n");
@lines = <ODD11>;# Read it into an array
foreach $line (@lines)
{
if ($line =~ /giccip/ && $FOUND == $FALSE )
{
#search for first giccip and replace it's value with new value
##### how to replace ???
$FOUND = $TRUE;
print ($line);
}
if ($line =~ /STC1NSAP/)
{
# How to replace ??
print ($line);
}
}
if ( $FOUND == $FALSE )
{
die("Can't find giccip");
}
close(ODD11);# Close the file
I've to search and replace the value of strings from a file.
The first string "giccip" can have multiple instances but i have to replace it's
value from the first instance only.
In the file "gicc" appear as follows, and it appears in the last of that line:
giccip=0x0a0600b0
The second string "STC1NSAP" has only one instance and i have to replace it's
value. It's on its own line
STC1NSAP=32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32
Here is my perl script
I'm on solaris
#!/usr/local/bin/perl -w
###########################################################
## This script changes the giccip address
## and STC1NSAP addresses in odd_persist file
###########################################################
#use warning;
#use strict;
my $FALSE = 0;
my $TRUE = 1;
my $FOUND = $FALSE;
my $odd11dir = "odd11";
my $odd11file = "odd11/odd_persist";
my $slot11ip = "0x0a0600b0";
my $STC1NSAP12 = "32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32.32";
### check if the script is run from the correct directory
### check if odd_persist files exist in odd1 & odd12 dirs
if (! -e $odd11dir)
{
die("directory $odd11dir not found \n");
}
if ( ! -e $odd11file )
{
die("$odd11file file doesn't exist \n");
}
### open odd11/persist file and replace first giccip address with correct value
### and replace STC1NSAP Address
open(ODD11, $odd11file) || die("can't open $odd11file : $!\n");
@lines = <ODD11>;# Read it into an array
foreach $line (@lines)
{
if ($line =~ /giccip/ && $FOUND == $FALSE )
{
#search for first giccip and replace it's value with new value
##### how to replace ???
$FOUND = $TRUE;
print ($line);
}
if ($line =~ /STC1NSAP/)
{
# How to replace ??
print ($line);
}
}
if ( $FOUND == $FALSE )
{
die("Can't find giccip");
}
close(ODD11);# Close the file