On Fri, 20 Feb 2004, Richard Eibrand wrote:
> The full script is as follows
>> gawk ' BEGIN { FS ="," } $2 ~ /-/ {DATE=$2} \
> $1 ~ /^[0-9][0-9][0-9]/ {DIST=$1} \
> $1 ~ /^1./ {POS=$0} \
> $1 ~ /^2./ {POS=$0} \
> $1 ~ /^3./ {POS=$0} \
> {print DATE","DIST","POS1}' test-res
>> The sample input follows
> , 30-Aug-03 , Galway:
> Race 1
> Pos.,Trap,Greyhound,Prize,Wt.,Dist,By Time,SP.,Comm.
> 525
> Going: Sand,Type: Flat,Handicap: 0
> 1.,Trap 5 ,MI PIPPIN,EUR500,57,, 30.20, 2/1,SlAw,Ld 3
> 2.,Trap 1 ,QUICK BILLY,EUR100,76,5L,30.55, 4/1,EP,Chl 2
> 3.,Trap 3 ,LYNNWOOD AIDE,EUR50,60,hd,30.56, 3/1,CrdRu,RnOn
> 4.,Trap 6 ,SEEKERS HILL,, 61,hd,30.57, 6/4,EvAw,WBnds
> 5.,Trap 2 ,MAGS BIKE,, 54,hd,30.58, 4/1,EvAw,EvCh
> 6.,Trap 4 ,DRUMANEEN DUKE,, 72,0.5L,30.61, 3/1,FAw,Imp 3
>> which repeats for a number of races.
Ah. Btw, /^1./ matches ^11, ^12, etc. the . is "any character" in a
regexp :)
How about..
BEGIN { FS = "," }
$2 ~ /^[0-9]?[0-9]-...-[0-9][0-9]^/ { {DATE=$1 }
$1 ~ /[0-9]+/ && NF == 1 { DIST=$1 }
$1 ~ /^[0-9]+\./ && $2 ~ /^Trap/ { POS=$0; }
{ printf ("%s, %s, %s\n", DATE, DIST, POS) }
Ie make the patterns "tighter", more specific and less likely to
spuriously match lines they werent meant to match. (which i suspect
might have been the problem.. possibly. :) - though, you only
printed in one action though. hmm..)
> Cheers, R
regards,
--
Paul Jakma paul at clubi.iepaul at jakma.org Key ID: 64A2FF6A
warning: do not ever send email to spam at dishone.st
Fortune:
To give of yourself, you must first know yourself.
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!