Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6176723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:09:04+00:00 2026-05-24T00:09:04+00:00

I have an interesting log file format and I would like to parse it

  • 0

I have an interesting log file format and I would like to parse it into Python for analysis.

The format is key=value with each separated by tabs, and a newline at the end of each entry, like this:

date="Mon, 04 Jul 2011 05:05:45 GMT"    addr=127.0.0.1  response_time=13    method=GET  url=/   status=200  referrer=   user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30"

Now some of the fields may be changing, so I want the code to be flexible with what is thrown at it, as long as it is in the form of key=value key=value(etc.)

As of now, I have two embedded for loops, one to split each line into the key=value fields, and the other to split the key=value into their own separate entities.

Does this seem like the best way to go or is there a more elegant solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:09:05+00:00Added an answer on May 24, 2026 at 12:09 am

    Two for loops seems fine for this problem. If I were coding it, I’d probably do something like this:

    with open('log_file') as f:
        for line in f:
            fields = line.split('\t')
            for field in fields:
                key,_,val = field.partition('=')
                # Do something with each key and val
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a revision hash key. I would like to get the closest revision
I have an interesting problem and would appreciate your thoughts for the best solution.
I have one interesting problem. I must parse mail body (regular expression), get some
Here's an interesting problem: I have some jQuery that looks like this: $(document).ready(function() {
So I'm running into an interesting issue implementing session ID rolling after log-in/change of
This sounds like a issue a beginner like me would only have...this is my
Typical Event Log message looks like below. There you can find very interesting fields
I have few log files around 100MBs each. Personally I find it cumbersome to
So we ran into an interesting issue today. We have a Java EE web
I have somewhat interesting development situation. The client and deployment server are inside a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.