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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cut string from the text file

Status
Not open for further replies.

1yura1

Programmer
Feb 7, 2003
36
UA
I have the string - "Some string". And I need to cut (delete, remoove) it from the text file.
 
open(IN, "textfile") or die "cannot open textfile\n";
open(OUT,">temporarytextfile") or die "cannot open temporarytextfile");
my $searchstring="Some string";
while(<IN>){
my $line=$_;
$line=~s/$searchstring//; #replace it with null string
print OUT &quot;$line&quot;;}
#now delete textfile
unlink &quot;textfile&quot;;
#and replace it by temporarytextfile this can be done
# via a system call, so let's first determine OS
my $Operating_system=$^O;
$Operating_system=uc($Operating_system);
unless($Operating_system=~/MSWIN32/){
system (&quot;mv temporarytextfile textfile&quot;);#use the Unix move function
}else{#a Windows machine..
system (&quot;copy temporarytextfile textfile&quot;);#
system (&quot;delete temporarytextfile&quot;);
}

hope this helps,
svar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top