[Za-pm] Script
Oskar Pearson
oskar at qualica.com
Wed Jun 4 06:52:17 CDT 2003
On Wed, Jun 04, 2003 at 01:40:05PM +0200, Spike wrote:
> 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!
Or just do it on the command line like awk. :)
oskar at core1:~$ perl -p -e '$_ =~ /^\[(.+)\] SMS +(.+) sent (.+) characters to (.+)$/; $_ = "$1 $2 $3 $4\n";' < t.txt
Fri May 23 11:02:12 SAST 2003 user at domain.co.za 43 271234567891
Fri May 23 18:16:02 SAST 2003 "Some User" <user at domain.co.za> 150 271234567891
Sat May 24 12:51:37 SAST 2003 "Some User" <user at domain.co.za> 151 271234567891
Mon May 26 15:16:00 SAST 2003 Some User <user at domain.co.za> 142 271234567891
oskar at core1:~$
Oskar
--
Oskar Pearson <oskar at qualica.com>
Qualica Technologies (Pty) Ltd
web: http://www.qualica.com/
More information about the Za-pm
mailing list