[Za-pm] Script

Spike spikeh at mweb.co.za
Wed Jun 4 06:40:05 CDT 2003


or you could try:-


[Fri May 23 11:02:12 SAST 2003] SMS  user at domain.co.za sent 43 characters 
to 271234567891

while (<>}
{
         chomp;

         /[(.+)]\s+SMS\s+(+.)\s+sent\s+(\d+)\s+characters to\s+(\d+)/ || next;

# \s+ just in case the spaces are tabs or multiple spaces
# contents of () are in $1,$2,etc

         $date =       $1;
         $e-mail =     $2;
         $char_count = $3;
         $phone =      $4;

         $total_char_count += $char_count;

# do something

}

Regex are cool - you can do everything twenty different ways!

At 2003/06/04 01:17 PM, Oskar Pearson wrote:
>On Wed, Jun 04, 2003 at 08:33:33AM +0200, Bartho Saaiman wrote:
> > I want to filter a log file that I currently have to manipulate
> > manually. So I was thinking to myself that this would be nice if I could
> > do this with Perl. If it would be easier in bash, suggestions would also
> > be welcome. So here is the scenario:
> >
> > Output of log file (sms.log):
> > <snip>
> > [Fri May 23 11:02:12 SAST 2003] SMS  user at domain.co.za sent 43
> > characters to 271234567891
> > [Fri May 23 18:16:02 SAST 2003] SMS  "Some User" <user at domain.co.za>
> > sent 150 characters to 271234567891
> > [Sat May 24 12:51:37 SAST 2003] SMS  "Some User" <user at domain.co.za>
> > sent 151 characters to 271234567891
> > [Mon May 26 15:16:00 SAST 2003] SMS  Some User <user at domain.co.za> sent
> > 142 characters to 271234567891
> > </snip>
> >
> > So the first problem is that the user (Some User) detail is logged in
> > three different ways. I am also only interested in the email addres as I
> > can use this to do accountting with. I am currentl using bash like this:
> >
> > [bartho at hercules bartho]$ cat  smslog |grep "May"| grep "2003" |awk \
> >       '{print $8, $9, $10}'
> > user at domain.co.za sent 47
> > "Some User" <user at domain.co.za>
> > Some User <user at domain.co.za>
> >
> > Now this is where my problem starts. I probably need to use regular
> > expressions to feed it the month and the domain. The year I could
> > probably use in a regex too, but this doesn't change to often. Then I
> > ned to send this to a clean file only containing the emails that this
> > originated from. I do not need to sort them as unique since I have to
> > add them up, similar to 'wc -l'
>
>I'm not sure I understand the output you want, I'm afraid. I'm also
>assuming that the log lines above weren't meant to be wrapped? (ie
>they were one long line)
>
>how about something like this:
>
>oskar at core1:~$ cat t.txt
>[Fri May 23 11:02:12 SAST 2003] SMS  user at domain.co.za sent 43 characters 
>to 271234567891
>[Fri May 23 18:16:02 SAST 2003] SMS  "Some User" <user at domain.co.za> sent 
>150 characters to 271234567891
>[Sat May 24 12:51:37 SAST 2003] SMS  "Some User" <user at domain.co.za> sent 
>151 characters to 271234567891
>[Mon May 26 15:16:00 SAST 2003] SMS  Some User <user at domain.co.za> sent 
>142 characters to 271234567891
>oskar at core1:~$ cat t.pl
>while (<STDIN>) {
>         my ($date, $address, $characters, $cell) =
>                 $_ =~ /^\[(.+)\] SMS +(.+) sent (.+) characters to (.+)$/;
>         print "$cell no, $characters chars (from $address at $date)\n";
>}
>oskar at core1:~$ perl t.pl < t.txt
>271234567891 no, 43 chars (from user at domain.co.za at Fri May 23 11:02:12 
>SAST 2003)
>271234567891 no, 150 chars (from "Some User" <user at domain.co.za> at Fri 
>May 23 18:16:02 SAST 2003)
>271234567891 no, 151 chars (from "Some User" <user at domain.co.za> at Sat 
>May 24 12:51:37 SAST 2003)
>271234567891 no, 142 chars (from Some User <user at domain.co.za> at Mon May 
>26 15:16:00 SAST 2003)
>oskar at core1:~$
>
>Oskar
>--
>Oskar Pearson <oskar at qualica.com>
>Qualica Technologies (Pty) Ltd
>web: http://www.qualica.com/
>_______________________________________________
>Za-pm mailing list
>Za-pm at mail.pm.org
>http://mail.pm.org/mailman/listinfo/za-pm


Spike Hodge

UNIX Programmer
M-Web Technology
021 596 8496
082 901 5265

Click here and make M-Web your homepage
http://homepage.mweb.co.za 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/za-pm/attachments/20030604/65c3ba19/attachment.htm


More information about the Za-pm mailing list