<html>
<body>
or you could try:-<br><br>
<br>
[Fri May 23 11:02:12 SAST 2003] SMS user@domain.co.za sent 43
characters to 271234567891<br><br>
<tt>while (<>}<br>
{<br>
<x-tab> </x-tab>chomp;<br><br>
<x-tab> </x-tab>/[(.+)]\s+SMS\s+(+.)\s+sent\s+(\d+)\s+characters
to\s+(\d+)/ || next;<br><br>
# \s+ just in case the spaces are tabs or multiple spaces<br>
# contents of () are in $1,$2,etc<br><br>
<x-tab> </x-tab>$date
= $1;<br>
<x-tab> </x-tab>$e-mail
= $2;<br>
<x-tab> </x-tab>$char_count
= $3;<br>
<x-tab> </x-tab>$phone
= $4;<br>
<x-tab> </x-tab><br>
<x-tab> </x-tab>$total_char_count
+= $char_count;<br><br>
# do something <br><br>
}<br><br>
</tt>Regex are cool - you can do everything twenty different
ways!<br><br>
At 2003/06/04 01:17 PM, Oskar Pearson wrote:<br>
<blockquote type=cite class=cite cite>On Wed, Jun 04, 2003 at 08:33:33AM
+0200, Bartho Saaiman wrote:<br>
> I want to filter a log file that I currently have to
manipulate<br>
> manually. So I was thinking to myself that this would be nice if I
could<br>
> do this with Perl. If it would be easier in bash, suggestions would
also<br>
> be welcome. So here is the scenario:<br>
> <br>
> Output of log file (sms.log):<br>
> <snip><br>
> [Fri May 23 11:02:12 SAST 2003] SMS user@domain.co.za sent
43<br>
> characters to 271234567891<br>
> [Fri May 23 18:16:02 SAST 2003] SMS "Some User"
<user@domain.co.za><br>
> sent 150 characters to 271234567891<br>
> [Sat May 24 12:51:37 SAST 2003] SMS "Some User"
<user@domain.co.za><br>
> sent 151 characters to 271234567891<br>
> [Mon May 26 15:16:00 SAST 2003] SMS Some User
<user@domain.co.za> sent<br>
> 142 characters to 271234567891<br>
> </snip><br>
> <br>
> So the first problem is that the user (Some User) detail is logged
in<br>
> three different ways. I am also only interested in the email addres
as I<br>
> can use this to do accountting with. I am currentl using bash like
this:<br>
> <br>
> [bartho@hercules bartho]$ cat smslog |grep "May"|
grep "2003" |awk \<br>
> <x-tab> </x-tab>'{print $8, $9,
$10}'<br>
> user@domain.co.za sent 47<br>
> "Some User" <user@domain.co.za><br>
> Some User <user@domain.co.za><br>
> <br>
> Now this is where my problem starts. I probably need to use
regular<br>
> expressions to feed it the month and the domain. The year I
could<br>
> probably use in a regex too, but this doesn't change to often. Then
I<br>
> ned to send this to a clean file only containing the emails that
this<br>
> originated from. I do not need to sort them as unique since I have
to<br>
> add them up, similar to 'wc -l'<br><br>
I'm not sure I understand the output you want, I'm afraid. I'm also<br>
assuming that the log lines above weren't meant to be wrapped? (ie<br>
they were one long line)<br><br>
how about something like this:<br><br>
oskar@core1:~$ cat t.txt<br>
[Fri May 23 11:02:12 SAST 2003] SMS user@domain.co.za sent 43
characters to 271234567891<br>
[Fri May 23 18:16:02 SAST 2003] SMS "Some User"
<user@domain.co.za> sent 150 characters to 271234567891<br>
[Sat May 24 12:51:37 SAST 2003] SMS "Some User"
<user@domain.co.za> sent 151 characters to 271234567891<br>
[Mon May 26 15:16:00 SAST 2003] SMS Some User
<user@domain.co.za> sent 142 characters to 271234567891<br>
oskar@core1:~$ cat t.pl<br>
while (<STDIN>) {<br>
my ($date, $address,
$characters, $cell) =<br>
$_ =~ /^\[(.+)\] SMS +(.+) sent (.+) characters to (.+)$/;<br>
print "$cell no,
$characters chars (from $address at $date)\n";<br>
}<br>
oskar@core1:~$ perl t.pl < t.txt<br>
271234567891 no, 43 chars (from user@domain.co.za at Fri May 23 11:02:12
SAST 2003)<br>
271234567891 no, 150 chars (from "Some User"
<user@domain.co.za> at Fri May 23 18:16:02 SAST 2003)<br>
271234567891 no, 151 chars (from "Some User"
<user@domain.co.za> at Sat May 24 12:51:37 SAST 2003)<br>
271234567891 no, 142 chars (from Some User <user@domain.co.za> at
Mon May 26 15:16:00 SAST 2003)<br>
oskar@core1:~$<br><br>
Oskar<br>
--<br>
Oskar Pearson <oskar@qualica.com><br>
Qualica Technologies (Pty) Ltd<br>
web:
<a href="http://www.qualica.com/" eudora="autourl">http://www.qualica.com/</a><br>
_______________________________________________<br>
Za-pm mailing list<br>
Za-pm@mail.pm.org<br>
<a href="http://mail.pm.org/mailman/listinfo/za-pm" eudora="autourl">http://mail.pm.org/mailman/listinfo/za-pm</a>
</blockquote>
<x-sigsep><p></x-sigsep>
<tt><br>
<font face="Courier New, Courier" size=2>Spike Hodge<br><br>
UNIX Programmer<br>
</font></tt><font face="Courier New, Courier" size=2>M-Web Technology<br>
</font><tt>021 596 8496<br>
082 901 5265<br><br>
</tt>Click here and make M-Web your homepage<br>
<a href="http://homepage.mweb.co.za/" eudora="autourl">http://homepage.mweb.co.za</a></body>
</html>