[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