Help with parsing a file please.
Posted: Sun Feb 21, 2010 12:07 pm
Hi all.
I'm Dave and I am new to the forum.
I was wondering if anyone could help?
I have a need to parse a log file and I am lost. I wonder if there is some kind soul that could help me with this task.
I have a log file:
And need to parse the file to extract only the info in red date, time, callsign(my) and name(sfx)), into an array I can work with, then alter the format of the date and time to make it sql compatible and place the data into a database table.
Every other line in the log contains the data I need.
I am ok with the database side of things and I could work with the data from an array, manipulate it and place in the DB, but it is the parsing of the file into an array that I am lost with.
TIA
Dave
I'm Dave and I am new to the forum.
I was wondering if anyone could help?
I have a need to parse a log file and I am lost. I wonder if there is some kind soul that could help me with this task.
I have a log file:
Code: Select all
022110 at 15:39:11:Is Postgres running?
022110 at 15:39:11:Yes, Postgres is running
022110 at 15:39:11:Reading file *****
022110 at 15:39:11:OWNER=[***** ]
022110 at 15:39:11:EXTERNAL_IF=[eth0]
022110 at 15:39:11:GW_PORT=[40000]
022110 at 15:39:11:INTERNAL_IF=[eth1]
022110 at 15:39:11:G2_INTERNAL_PORT=[20000]
022110 at 15:39:11:TO_RPTR_IP=[*******]
022110 at 15:39:11:RPTR_PORT=[20000]
022110 at 15:39:11:PORT_RENEWALS=[12346]
022110 at 15:39:11:QSO_DETAILS=[Y]
022110 at 15:39:11:EXTERNAL_IF eth0 has private IP *********
022110 at 15:39:11:INTERNAL_IF eth1 has private IP *********
022110 at 15:39:11:dstar_g2_gwy v2.45 initialized...entering processing loop
[color=#BF0000]022110[/color] at [color=#BF0000]15:39:4[/color]8:START from rptr: cntr=53 ac, streamID=80,58, flags=00:00:00, my=[color=#BF0000]callsign[/color] , sfx=[color=#BF0000]name[/color] , ur=CQCQCQ , rpt1=GB3IN C, rpt2=GB3IN G, 58 bytes fromIP=172.16.0.2
022110 at 15:39:49:END from rptr: cntr=53 f8, streamID=80,58, 32 bytes
022110 at 15:39:53:START from rptr: cntr=53 fa, streamID=84,45, flags=00:00:00, my=G4TSN , sfx=JON , ur=CQCQCQ , rpt1=GB3IN C, rpt2=GB3IN G, 58 bytes fromIP=172.16.0.2
022110 at 15:39:55:END from rptr: cntr=54 68, streamID=84,45, 32 bytes
022110 at 15:40:02:START from rptr: cntr=54 6a, streamID=25,84, flags=00:00:00, my=G1ZGZ , sfx=RICK, ur=CQCQCQ , rpt1=GB3IN C, rpt2=GB3IN G, 58 bytes fromIP=172.16.0.2
022110 at 15:40:05:END from rptr: cntr=55 12, streamID=25,84, 32 bytes
022110 at 15:41:20:START from rptr: cntr=55 16, streamID=107,204, flags=00:00:00, my=G4TSN , sfx=JON , ur= U, rpt1=GB3IN C, rpt2=GB3IN G, 58 bytes fromIP=172.16.0.2
022110 at 15:41:21:END from rptr: cntr=55 4c, streamID=107,204, 32 bytes
022110 at 15:41:21:START from g2: cntr=00 00, streamID=20,134, flags=00:00:00, my=GB3IN , sfx=RPTR, ur=CQCQCQ , rpt1=GB3IN C, rpt2=GB3IN G, 56 bytes fromIP=82.153.52.51
022110 at 15:41:23:END from g2: cntr=00 65, streamID=20,134, 27 bytes from IP=82.153.52.51
022110 at 15:43:52:START from rptr: cntr=55 50, streamID=15,202, flags=00:00:00, my=G4TSN , sfx=JON , ur= U, rpt1=GB3IN C, rpt2=GB3IN G, 58 bytes fromIP=172.16.0.2
022110 at 15:43:52:END from rptr: cntr=55 63, streamID=15,202, 32 bytes
Every other line in the log contains the data I need.
I am ok with the database side of things and I could work with the data from an array, manipulate it and place in the DB, but it is the parsing of the file into an array that I am lost with.
TIA
Dave