LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] awk question

[ILUG] awk question

Richard Eibrand richard at eibrand.net
Fri Feb 20 22:15:28 GMT 2004


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.

>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..."



More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


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!
RSS Version
Powered by Dell