The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Regex Programming
|
Select specific field from CSV
Discuss Select specific field from CSV in the Regex Programming forum on Dev Shed. Select specific field from CSV Regular expressions forum covering PCRE and POSIX techniques, practices, and standards. Regular expressions help shorten coding time by providing the ability to compact many lines of code into one string.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 27th, 2009, 09:00 AM
|
|
Registered User
|
|
Join Date: Jan 2009
Posts: 3
Time spent in forums: 40 m 4 sec
Reputation Power: 0
|
|
|
Select specific field from CSV
Hi,
I am not using regex alongside another language it is infact used in an application I am running and trying to customize. Its basically a firewall log.
I have a csv:
<25>Jan 23 03:52:57 192.168.27.200 20090123, 9380690, 2009/01/23 10:52:54, 2009/01/23 10:52:53, global.devices, 499, mydevice, 0.0.0.0, traffic, traffic log, trust, (NULL), 10.1.2.6, 4021, 216.141.86.226, 1516, untrust, (NULL), 216.34.209.13, 80, 216.34.209.13, 80, tcp, global.devices, 499, Combined-Demo, fw/vpn, 32, accepted, info, no, Close - TCP FIN, (NULL), (NULL), (NULL), 1, 853, 715, 1568, 0, 0, 10, 1, no, 0, Not Set, sos
and I want to extract fields by selecting field 5 which should be global.devices. Field 5 could have anything in here not just english chars and .'s. I would like to use this construction to eventually pick any field I want out of the csv, not just 5.
Any help here greatly appreciated - I have tried allsorts but to no avail.
|

January 27th, 2009, 04:52 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
If there are commas in one of the fields (and so it has quotes around it) it'll be more complicated.
When asking for regex help it's always nice to tell us what flavor of regex it is. They're all subtly different. Or in your case, what program you're using.
$2 is the field you want, regardless of what number you have in the {}s.
|

January 27th, 2009, 05:24 PM
|
|
Registered User
|
|
Join Date: Jan 2009
Posts: 3
Time spent in forums: 40 m 4 sec
Reputation Power: 0
|
|
|
Thanks I will try that when I am in the office tomorrow. The program is radar by q1labs and I have no idea what version of regex it is.
|

January 28th, 2009, 10:48 AM
|
|
Registered User
|
|
Join Date: Jan 2009
Posts: 3
Time spent in forums: 40 m 4 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by andydouth Thanks I will try that when I am in the office tomorrow. The program is radar by q1labs and I have no idea what version of regex it is. |
This is so close !
It is selecting the , on the end is there a simple way of removing this?
Thanks
|

January 28th, 2009, 03:46 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
Hmm, you must be using it a bit differently than I thought.
Code:
^\s*[^,]*(,\s*([^,]*)){4}
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|