I am receiving some lines of log, to which I generate a header with the data of some of the fields, as the first ip in the line.
To do this use a split of empty spaces and so I could select the information I wanted to use in the header.
But I realized that when the day of the log is less than 10 instead of writing the number with a leading zero, another empty space is generated and the script fails, because instead of selecting the ip, select the time.
For example, given these two lines with different dates:
< 7 > Feb 28 20:06:09 113.78.60.60 1,2013 / 06/02 00: 04: 03,891701036531, sunny, 0,
< 7 > Feb 8 20:06:09 113.78.60.60 1,2013 / 06/02 00: 04: 03,891701036531, sunny, 0,
By using the following code:
import sys
import time
Log = sys.stdin.readline()
Ip = Log.split(' ')[3]
print Ip + ',' + Log
with the first string the Ip is captured without problems ("113.78.60.60") but with the second one what is obtained is the time ("20:06:09").