Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can not find a string

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Joined
Feb 6, 2002
Messages
1,851
Location
IL
HI,

Got a file that contains lines like :

[HKEY_LOCAL_MACHINE\Software\Creo\Araxi\Settings\Default\DASS\Services\Ceps_1]
"Model"="CEPSConversion"
"Host"="YCS90317-9825"
"Features"="44;43"
"Installed"=dword:00000001
"Pool"=dword:00000000
"Offline"=dword:00000000

In code I search for lines that contain "Host"=" nad try establishing the host name that follows.
Whatever regexes I try - both print expressions print nothing,seemingly not finding the string:

open (FILE,'Araxi.reg') || die "Could not open Araxi.reg: $!";
while (<FILE>) {
chomp;
if ($_ =~ /\"Host\"=\"/) {
print "$_\n";
($NEWNAME) = m/\"Host\"=\"(\w*?)\"/;
print "NEWNAME=$NEWNAME\n";
last;
}
}

Any ideas ?
Thanks


Long live king Moshiach !
 
Code:
    while (<DATA>) {
        chomp;
        if (/"Host"="/) {
            print "$_\n";
            ($host,$newname)=split(/=/, $_);
            $newname=~s/"//g;
            print "NEWNAME=$newname\n";
            last;
        }
    }
__DATA__
[HKEY_LOCAL_MACHINE\Software\Creo\Araxi\Settings\Default\DASS\Services\Ceps_1]
"Model"="CEPSConversion"
"Host"="YCS90317-9825"
"Features"="44;43"
"Installed"=dword:00000001
"Pool"=dword:00000000
"Offline"=dword:00000000

This'll give you what you need until someone can sort out your regex, there no need to escape the quotes in a regex, that's part of the problem

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Thanks,

I have playrd with Regex,the problem does not seem to be there.

Even if I go for

if (/Host/)

still prints nothing.
It really looks like a unicode issue.
I need help encoding decoding the file properly.
Thanks

Long live king Moshiach !
 
Code:
        if (/"Host"="/) {
are you using this line?

If it's a unicode problem, which I doubt, try printing what's been read for say the first 10 lines to the screen, to see if there's a problem with double byte characters.

Is there any chance that you've modified $/ so the whole file is in $_ after the first read?

HTH

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
HI,

1.It does look like UNICODE issue.
Word says that this Windows registry file IS UNICODE.
Printing several lines shows:

[ H K E Y _ L O C A L _ M A C H I N E \

while in Notepad the line looks like:

[HKEY_LOCAL_MACHINE\

2.I have not changed the $/.

Long live king Moshiach !
 
Thanks,

ended up using:

open (FILE,'<:encoding(utf16)',"Araxi.reg") || die "Could not open Araxi.reg: $!";

However now another problem:

Now I want to replace strings in the file and write it back in utf16 to Araxi2.reg.
I use the code below,but the file does not look good in Notepad anymore,meaning the format is not exactly utf16 ...


open (FILE,'<:encoding(utf16)',"Araxi.reg") || die "Could not open Araxi.reg: $!"; #Read UNICODE FILE TO ASCII
open (FILE1,">Araxi1.reg") || die "Could not open Araxi1.reg: $!";
while (<FILE>) {
print FILE1;
}
close FILE;
close FILE1;


open (FILE1,"Araxi1.reg") || die "Could not open Araxi1.reg: $!"; #get old server name
while (<FILE1>) {
chomp;
if (/Host/) {
($OLDNAME) = m/"Host"="(\w*-\w*)"/;
$OLDNAME_SMALL = lc $OLDNAME;
last;
}
}
close FILE1;


open (FILE,'>:encoding(utf16)',"Araxi2.reg") || die "Could not open Araxi2.reg: $!"; #CONVERT A UNICODE FILE TO ASCII
open (FILE1,"Araxi1.reg") || die "Could not open Araxi1.reg: $!";
while (<FILE1>) {

s/OLDNAME/computer/;
s/$OLDNAME_SMALL/computer_small/;
print FILE "$_";
}




Long live king Moshiach !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top