Display all headersDate: Fri, 20 Feb 2004 23:09:19 -0000
To: Paul Jakma <paul at clubi.ie>, "ilug at linux.ie" <ilug at linux.ie>
Subject: Re: [ILUG] awk question
From: Richard Eibrand <richard at eibrand.net>
On Fri, 20 Feb 2004 20:13:34 +0000 (GMT), Paul Jakma <paul at clubi.ie> wrote:
Where are these lines?
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.
Every PATTERN in an awk script is tested against each record, so if
you have:
$1 ~ /^[123]/ { ACTION}
In my addendum, the line above was not included, that was a mistake on my
behalf.
$1 ~ /^1./ { ACTION}
However, you havnt fully specified what you are doing, nor provided
sample input.
What I need to do is to format the sample input above, into the format
shown below, the need for this is to
import the data into a mysql database. I only need/want the first three
lines of results, the rest I dont
want.
30-Aug-03 ,525 ,1.,Trap 1 ,LADY TEMPLE,EUR500,64,, 29.18, 9/4,EP,ALd
30-Aug-03 ,525 ,2.,Trap 5 ,HERSHAM STAR,EUR100,74,6L,29.60, 3/1,A 2nd,StyWl
30-Aug-03 ,525 ,3.,Trap 6 ,JA,EUR50,75,0.75L,29.65, 3/1,A 3rd,FinWl
each of which goes into their respective field.
Cheers, R
--
"Cogito Cogito ergo sum, but I'm not so sure..."
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!