For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > March 2005 > AW: Text Search/Delete









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author AW: Text Search/Delete
Krause Susanne

2005-03-30, 8:55 am

Hi Greg.

Its easy, just take:

########################################
#####
#!/usr/bin/perl

$file =3D "logfile";
$file_tmp =3D"tmp";

$a =3D "DSL";
$b=3D"No such user";

open (INPUT, $file) || die ("Could not open file: $!\n");
open (OUTPUT, " > $file_tmp" ) || die ("Could not open file: $!\n");

while (<INPUT> ) {
if (!($_ =3D~/$a/ && $_ =3D~/$b/)) {
print OUTPUT ("$_");
}
}


close( INPUT);
close(OUTPUT);

rename ($file_tmp, $file) ;

#####################################

Regards from Switzerland
Susanne

> -----Urspr=FCngliche Nachricht-----
> Von: Greg Schiedler [SMTP:Greg@Limo.Net]
> Gesendet am: Mittwoch, 30. M=E4rz 2005 08:47
> An: beginners-cgi@perl.org
> Betreff: Text Search/Delete
>=20
> OK I need to parse a rather large logfile and delete specific lines.
> The file is called logfile and is simply a large text file.
>=20
> Is there some simple way to read in the file and delete specific =

lines
> that contain DSL:user@domain.com and the rerun the process to delete
> user2@domain.com -or-
> Delete all lines that contain: "DSL:" and the text :No such user"
>=20
> Greg
>=20
>=20
> Sample logfile....
>=20
> Wed Jan 5 05:35:57 2005: DSL:user@domain.com::POP::No such user
> ....
> ....
> Sat Mar 26 08:54:04 2005: DSL:user2@domain.com::POP::No such user
> Sat Mar 26 08:54:10 2005: DSL:user2@domain.com::POP::No such user
> Sat Mar 26 08:54:16 2005: DSL:user2@domain.com::POP::No such user
> Sat Mar 26 08:54:23 2005: DSL:user2@domain.com::POP::No such user
> Sat Mar 26 08:54:29 2005: DSL:user2@domain.com::POP::No such user
> Sat Mar 26 08:54:35 2005: DSL:user2@domain.com::POP::No such user
> ...
> ...
>=20
>=20
> --=20
> To unsubscribe, e-mail: beginners-cgi-unsubscribe@perl.org
> For additional commands, e-mail: beginners-cgi-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>=20

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com