Txt file: Delete line - Delete line from txt file

They have: 62 posts

Joined: May 1999

Hi-
I need to be able to delete a line of text from a file when it meets certain search criteria...like if they say "stock", the line of text with "stock" in it gets deleted. Any ideas how to do this with Perl? Thanks!

----------
Casey Hansen
www.caseynet.com

They have: 62 posts

Joined: May 1999

Hi-
Could you please give me the full code to do this? (I am still kind of new to PERL) Smiling THANKS!

----------
Casey Hansen
www.caseynet.com

They have: 92 posts

Joined: May 1999

open(USERS,"./dc/users.txt" ) ;
@users=<USERS>;
close(USERS);

open(USERS,">./dc/users.txt" ) ¦¦ &error("Unable to write to ./dc/users.txt" ) ;
foreach $line (@users) {
# PLACE CRITERIA HERE
unless ($X eq $Y) {
print USERS $line;
}
}
close(USERS);

----------
Ted Sindzinski
www.infinityinternet.com www.solutionscripts.com

<<edited by Patrick Baer, to take out the smileys>>

Ted S

They have: 62 posts

Joined: May 1999

Hi-
What do I place in the CRITERIA comment spot? Remember, I'm a newbie Smiling

----------
Casey Hansen
www.caseynet.com

They have: 453 posts

Joined: Jan 1999

Hi,

change the
unless($X eq $Y){
to
unless($line =~ /stock/){

and you have what you wanted.

ciao
Anti

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.