View Full Version : Search,Replace
s022jsb
08-14-2003, 05:05 PM
hi all
i need to be able to search a file for a particular string and replace some of the text
ex, TEXT=???
"TEXT" is always the same
"=" alwsays comes after TEXT
??? is unknown
what i want to do is to search a file for that string and replace the
??? with "myinput" so i would then have
TEXT=myinput
ACJavascript
08-14-2003, 05:35 PM
you could do somthing like this
open(info,"yourFile.txt") || print "SOrry can't open yourFile.txt";
@in=<info>;
close(info);
chomp(@in);
foreach $i(@in){
$i =~ s/???/myinput/g;
}
open(update,">yourFile.txt" || print "can't open yourFile.txt";
flock(update,2);
seek(update,0,0);
print update @in;
close(update);
print "Success";
exit;
Didn't try it but i think it will work just fine.
s022jsb
08-14-2003, 05:36 PM
i will give it a shot, let you know if it works
thanks
s022jsb
08-14-2003, 05:40 PM
looking at the code,
in the search string ??? can be anything, name,date whaterver
wont' s/???/myinput look for the string "???", i need it to be able to change the data after the "=" in a typical line
TEXT=??? and ??? is unknown, it could be a name,date...
thanks again
jason
ACJavascript
08-14-2003, 08:51 PM
Okay how about this:
open(info,"yourFile.txt") || print "SOrry can't open yourFile.txt";
@in=<info>;
close(info);
chomp(@in);
foreach $i(@in){
$i =~ s/$FORM{'SearchInput'}/myinput/g;
}
open(update,">yourFile.txt" || print "can't open yourFile.txt";
flock(update,2);
seek(update,0,0);
print update @in;
close(update);
print "Success";
exit;
SearchInput is the name of the form field that would be the date or name or whatever...
s022jsb
08-14-2003, 08:56 PM
thanks
jason
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.