Split string but ignore quotes
bigblueswope at gmail.com
Wed Sep 30 02:33:21 CEST 2009
Would the csv module be appropriate?
On 9/29/09, Scooter <slbentley at gmail.com> wrote:
> I'm attempting to reformat an apache log file that was written with a
> custom output format. I'm attempting to get it to w3c format using a
> python script. The problem I'm having is the field-to-field matching.
> In my python code I'm using split with spaces as my delimiter. But it
> fails when it reaches the user agent because that field itself
> contains spaces. But that user agent is enclosed with double quotes.
> So is there a way to split on a certain delimiter but not to split
> within quoted words.
> i.e. a line might look like
> 2009-09-29 12:00:00 - GET / "Mozilla/4.0 (compatible; MSIE 7.0;
> Windows NT 6.0; GTB5; SLCC1; .NET CLR 2.0.50727; Media Center PC
> 5.0; .NET CLR 3.0.04506; .NET CLR 3.5.21022)" http://somehost.com 200
> 1923 1360 31715 -
To argue that honorable conduct is only required against an honorable
enemy degrades the Americans who must carry out the orders. -- Charles
Krulak, Former Commandant of the Marine Corps
We are all slave to our own paradigm. -- Joshua Williams
If the letters PhD appear after a person's name, that person will
remain outdoors even after it's started raining. -- Jeff Kay
More information about the Python-list