Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I have been trying to deal with some syslog files to store them in a DB but the format has just been too variable so I had another idea how to deal with them

My lines look like the following

May  2 04:06:15 lon-pop.mail.mydom.com pop3login: LOGOUT, user=gonenow, ip=[::ffff:127.0.0.1], top=0, retr=0, rcvd=24, sent=5560, time=1

The first three parts are pretty standard i.e. datetime( though with no year ) sysloghost, progname then the very variable message.

What I would like to do is convert this to a csv line as follows where its broken into at least four parts but if the string user=gonenow appears then add gonenow ( or whatever the users name was ) as an extra field, same for ip=

02/05/2012 04:06:15,lon-pop.mail.mydom.com,pop3login,"LOGOUT, user=gonenow, ip=[::ffff:127.0.0.1], top=0, retr=0, rcvd=24, sent=5560, time=1",gonenow,::ffff:127.0.0.1

I dont mind either way if I end up with empty fields or no fields at the end i.e. ,, or it just ends after the end quote of the message, but I have been banging my head trying to figure this for a few days


In reply to Syslog files revisited by stevbutt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-29 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found