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] Gawk query

[ILUG] Gawk query

Brian Foster blf at utvinternet.ie
Thu Aug 23 17:33:13 IST 2007


  | From: "Paschal Nee" <pnee at toombeola.com>
  | Date: Thu, 23 Aug 2007 17:03:34 +0100
  | 
  | Seems like a standard enough query but is there a way to get gawk to
  | recognise fields that are enclosed by a delimiter as single fields.
  | 
  | An example:
  | 
  | 10.129.141.1 - - [23/Aug/2007:16:06:14 +0100] "GET /hh HTTP/1.1" 200 1763
  | 10.129.141.1 - - [23/Aug/2007:16:06:14 +0100] "GET /hy HTTP/1.1" 200 1763
  | 10.129.141.1 - - [23/Aug/2007:16:06:14 +0100] "GET /hz HTTP/1.1" 200 1763
  | 10.129.141.1 - - [23/Aug/2007:16:06:14 +0100] "GET /hf HTTP/1.1" 200 1763
  | 
  |[ ... ] what I'm looking for would be
  | 
  | 10.129.141.1
  | -
  | -
  | 23/Aug/2007:16:06:14 +0100
  | GET /hh HTTP/1.1
  | 200
  | 1763
  | 
  | i.e. recognising that [] and "" enclose single fields.

 for the example given, this should do it:

    gawk -F'([][]| "|" | )' '{for (i=0;i<NF;i++) print $i}'

 and very quickly tested with “GNU Awk 3.1.3”.

 that will screw up if there is ever a [, ], "_, or _"
 (where _ means space) which is not a field delimiter.
 you can of course add tabs &tc if needed; and the ERE
 can be written in several different ways.  I'm unsure
 if the above will work with non-GNU nawk's or not?

cheers!
	-blf-
-- 
▶ ▶  I AM CURRENTLY LOOKING FOR A JOB!  ◀ ◀ | Brian Foster
Experienced (>25 yrs) software engineer:    |        Montpellier, FRANCE
 • Unix, Linux, embedded, design-for-test;  | Stop E$$o (ExxonMobile)!
 • Software/hardware co-design, debugging;  |     http:/www.stopesso.com
 • Kernels, drivers, filesystems, &tc;    Résumé (CV) & contact details:
 • IDL, automated testing, process, &tc.   http://www.blf.utvinternet.ie



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