On Sat, 21 Feb 2004 11:27:19 +0100, Brian Foster <blf at utvinternet.ie> wrote:
> I haven't following this very closely, but my understanding
> is the gawk(1) script in question is basically:
>> /RE?/ { x = $1; }
> /RE?/ { y = $3; }
> { print x, y; }
>> and the ?problem? is apparent-duplicate lines are printed.
Yep, thats it
> well, what else do you expect the script to do?
Sadly, not what it is actually doing... I'm new to awk
> the solution? below, I am assuming nothing is to be printed until all
of the values-to-print have been set,
Spot on
> and then the cycle repeats. this is _not_ robust, yer kiloage will vary!
>> BEGIN { state = 0; }
> /RE?/ { x = $1; state++; }
> /RE?/ { y = $3; state++; }
> state == 2 { print x, y; state = 0; }
Modifying your example to
BEGIN { state = 0; }{ FS ="," }
$2 ~ /-/ {DATE=$2; state++;}
$1 ~ /^[0-9][0-9][0-9]/ {DIST=$1; state++;}
$1 ~ /^[1-3]+\./ && $2 ~ /^Trap/ { POS=$0; state++;}
state == 3 { print DATE","DIST","POS; state = 0; }
Gives me the following output,
30-Aug-03,525 ,1.,Trap 5 ,MI PIPPIN,EUR500,57,, 30.20, 2/1,SlAw,Ld 3
30-Aug-03,525 ,3.,Trap 3 ,LYNNWOOD AIDE,EUR50,60,hd,30.56, 3/1,CrdRu,RnOn
30-Aug-03,525 ,3.,Trap 3 ,MISS THE TIME,EUR50,64,1.5L,30.77, 5/2,QAw,CrdRu
30-Aug-03,525 ,2.,Trap 4 ,FEDAMORE JO JO,EUR100,72,12L,30.43, 3/1,
CrdRu,FinWl
30-Aug-03,525 ,1.,Trap 3 ,TEN TO ELEVEN,EUR500,77,, 29.50, 2/1,DspLd,Ld 3
30-Aug-03,525 ,3.,Trap 4 ,FAST FIT TOM,EUR50,71,0.5L,29.78, 3/1,DspLd,RnOn
30-Aug-03,525 ,3.,Trap 6 ,FLEA,EUR100,73,nk,29.64, 4/1,FAw,CrdRi
30-Aug-03,525 ,2.,Trap 3 ,OLLYS SHAWL,EUR100,58,6L,30.02, 5/1,EP,Styd
30-Aug-03,525 ,1.,Trap 1 ,FIVE ALIVE FLASH,EUR500,71,, 29.29, 5/2,EP,ALd
30-Aug-03,550 ,3.,Trap 2 ,CLUANE CASPER,EUR50,66,9L,30.06, 2/1,EvAw,EvCh
30-Aug-03,550 ,3.,Trap 6 ,COOLIO,EUR100,70,3L,30.79, 2/1,W 1,Chl 3
30-Aug-03,525 ,2.,Trap 1 ,KALOOKI MAC,EUR100,81,1L,29.50, 5/2,EP,Ld 1
which is sadly different to the wanted output http://eibrand.net/wanted
The full input file is shown here http://eibrand.net/test-res
> this may not quite what is wanted, but is --- possibly ---
> close to what is intended?
Certainly closer to my previous attempts ;-)
Thanks for the input
> cheers!
Indeed, 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!