I wrote these lines to import zip file with log files in it:
from google.colab import drive
drive.mount('/content/drive')
from zipfile import ZipFile
df_ht = !unzip "/content/drive/MyDrive/HTWebLog_p1.zip"
To read the log file:
file = open('ex061101.log', 'r')
print(file)
output:
<_io.TextIOWrapper name='ex061101.log' mode='r' encoding='UTF-8'>
lines = file.read().splitlines()
lines[5:6]
Output:
['2006-11-01 00:00:08 W3SVC1 127.0.0.1 GET /Tulip/home/en-us/home_index.aspx - 80 - 70.80.84.76 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1) - 200 0 0']
Now I am trying to store the loop output, but I only get the last log file (judging by the length of it):
for i in range(212,229):
lines = (open(str('ex061') + str(i) + str('.log'), 'r', encoding='iso-8859-1')).read().splitlines()
len(lines)
EDIT.
I found the solution:
import itertools
lines = []
for i in range(212,229):
lines = (open(str('ex061') + str(i) + str('.log'), 'r', encoding='iso-8859-1')).read().splitlines()
output=list(itertools.chain(lines))
str(). You might even considerf"ex061{i}.log".