<html>
<body>
or you could try:-<br><br>
<br>
[Fri May 23 11:02:12 SAST 2003] SMS&nbsp; user@domain.co.za sent 43
characters to 271234567891<br><br>
<tt>while (&lt;&gt;}<br>
{<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>chomp;<br><br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>$date
=&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $1;<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>$e-mail
=&nbsp;&nbsp;&nbsp;&nbsp; $2;<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>$char_count
= $3;<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>$phone
=&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $4;<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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>
&gt; I want to filter a log file that I currently have to 
manipulate<br>
&gt; manually. So I was thinking to myself that this would be nice if I
could<br>
&gt; do this with Perl. If it would be easier in bash, suggestions would
also<br>
&gt; be welcome. So here is the scenario:<br>
&gt; <br>
&gt; Output of log file (sms.log):<br>
&gt; &lt;snip&gt;<br>
&gt; [Fri May 23 11:02:12 SAST 2003] SMS&nbsp; user@domain.co.za sent
43<br>
&gt; characters to 271234567891<br>
&gt; [Fri May 23 18:16:02 SAST 2003] SMS&nbsp; &quot;Some User&quot;
&lt;user@domain.co.za&gt;<br>
&gt; sent 150 characters to 271234567891<br>
&gt; [Sat May 24 12:51:37 SAST 2003] SMS&nbsp; &quot;Some User&quot;
&lt;user@domain.co.za&gt;<br>
&gt; sent 151 characters to 271234567891<br>
&gt; [Mon May 26 15:16:00 SAST 2003] SMS&nbsp; Some User
&lt;user@domain.co.za&gt; sent<br>
&gt; 142 characters to 271234567891<br>
&gt; &lt;/snip&gt;<br>
&gt; <br>
&gt; So the first problem is that the user (Some User) detail is logged
in<br>
&gt; three different ways. I am also only interested in the email addres
as I<br>
&gt; can use this to do accountting with. I am currentl using bash like
this:<br>
&gt; <br>
&gt; [bartho@hercules bartho]$ cat&nbsp; smslog |grep &quot;May&quot;|
grep &quot;2003&quot; |awk \<br>
&gt; <x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>'{print $8, $9,
$10}'<br>
&gt; user@domain.co.za sent 47<br>
&gt; &quot;Some User&quot; &lt;user@domain.co.za&gt;<br>
&gt; Some User &lt;user@domain.co.za&gt;<br>
&gt; <br>
&gt; Now this is where my problem starts. I probably need to use
regular<br>
&gt; expressions to feed it the month and the domain. The year I
could<br>
&gt; probably use in a regex too, but this doesn't change to often. Then
I<br>
&gt; ned to send this to a clean file only containing the emails that
this<br>
&gt; originated from. I do not need to sort them as unique since I have
to<br>
&gt; 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&nbsp; user@domain.co.za sent 43
characters to 271234567891<br>
[Fri May 23 18:16:02 SAST 2003] SMS&nbsp; &quot;Some User&quot;
&lt;user@domain.co.za&gt; sent 150 characters to 271234567891<br>
[Sat May 24 12:51:37 SAST 2003] SMS&nbsp; &quot;Some User&quot;
&lt;user@domain.co.za&gt; sent 151 characters to 271234567891<br>
[Mon May 26 15:16:00 SAST 2003] SMS&nbsp; Some User
&lt;user@domain.co.za&gt; sent 142 characters to 271234567891<br>
oskar@core1:~$ cat t.pl<br>
while (&lt;STDIN&gt;) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my ($date, $address,
$characters, $cell) =<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$_ =~ /^\[(.+)\] SMS +(.+) sent (.+) characters to (.+)$/;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;$cell no,
$characters chars (from $address at $date)\n&quot;;<br>
}<br>
oskar@core1:~$ perl t.pl &lt; 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 &quot;Some User&quot;
&lt;user@domain.co.za&gt; at Fri May 23 18:16:02 SAST 2003)<br>
271234567891 no, 151 chars (from &quot;Some User&quot;
&lt;user@domain.co.za&gt; at Sat May 24 12:51:37 SAST 2003)<br>
271234567891 no, 142 chars (from Some User &lt;user@domain.co.za&gt; at
Mon May 26 15:16:00 SAST 2003)<br>
oskar@core1:~$<br><br>
Oskar<br>
--<br>
Oskar Pearson &lt;oskar@qualica.com&gt;<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>