Originally Posted by
katharnakh
Hi,
Please go through this, before posting your code. Its not an assignment, just a prerequisite if you want to get really quick help.
Only with code it is hard to know what is working and what is not. Provide some input(example) details. Post your errors, if any OR if you are getting output, post it and explain, how you want it to be or how different it is from what you want.
katharnakh.
hello,
i have written the code, but the output is not coming properly.
i have to write a script which can automatically update the old file with new values. for example, i have a file which has few commands in it along with other data( like vdd_power; ac_current,etc). now i have to replace these values in that file with the new values(like vddPOWER;AC_current).and everytime i run the script on such file, it should automatically update the file.
when i run this code, i m getting the file with the replaced values but the file is now containing only the new values, all the old data has been overwritten with the new one.and also i have hard coded it.is there any other way to do it? plz help me .
thanks & ragards
Nisha
the code is:-
#!/grid/comon/bin/perl
$dir="../nishap";
$sub="nisha";
$path="$dir/$sub/$file";
#print "$path\n";
open(OLD_DATA1,"$path") or die("cant open the file $path");
#open(OLD_DATA,"../nishap/nisha/old_data.txt") || die "cant open the file $path";
while($line=<OLD_DATA1>)
{
chomp($line);
if($line =~/^abc_xyz_cwd$/)
#if($line =~/^(\w+(.*))$/)
{
# print "$line\n";
$data1=$line;
$data1=~s/abc_xyz_cwd/abc_xyzcwd/gi;
print "$data1\n";
}
if($line=~/^aa_aa$/)
# if($line =~/^(\w+(.*))$/) ----is this correct??
{
$data2=$line;
$data2=~s/aa_aa/aaaa/gi;
print"$data2\n";
}
if($line=~/^bb$/)
{
#print"$line";
$data3=$line;
$data3=~s/bb/b_b/gi;
print"$data3\n";
}
if($line=~/^c_c$/)
{
$data4=$line;
$data4=~s/c_c/cc/gi;
print"$data4\n";
}
if($line=~/^dd_ee$/)
{
$data5=$line;
$data5=~s/dd_ee/dde_e/gi;
print"$data5\n";
}
}
close(OLD_DATA1);
$new="old_data1.txt";
open(OLD_DATA1,">>../nishap/nisha/old_data1.txt") or die("cant open the file $new");
{
print OLD_DATA1 "
$data1
$data2
$data3
$data4
$data5
\n ";
}
close(OLD_DATA1);