Reputation: 99
I have a file,
6802496011442316593 1625090609 51048468525236 aaa=1111|bbbb=15|cccc=216|dddd=1625090604|eeee=5|ffff=12000|ggg=brtnrn=|hhhh=4|ii=lfp|ts=1625090609
6802496011442316593 1625090609 51048468525236 aaa=1111|bbbb=15|cccc=216|dddd=1625090604|eeee=5|ffff=12000|ggg=brtnrn=|hhhh=4|ii=lfp|ts=1625090489
6802496011442316593 1625090609 51048468525236 aaa=1111|bbbb=15|cccc=216|dddd=1625090604|eeee=5|ffff=12000|ggg=brtnrn=|hhhh=4|ii=lfp|ts=1625090549
6802496011442316593 1625090609 51048468525236 aaa=1111|bbbb=15|cccc=216|dddd=1625090604|eeee=5|ffff=12000|ggg=brtnrn=|hhhh=4|ii=lfp|ts=1625090599
6802496011442316593 1625090609 51048468525236 aaa=1111|bbbb=15|cccc=216|dddd=1625090604|eeee=5|ffff=12000|ggg=brtnrn=|hhhh=4|ii=lfp|ts=1625090599
from which I am extracting the last element "ts=1625090609" without "ts=":
with open(inputt, "r") as f1:
for line in f1:
exp=(line.split("\t")[3])
params=(exp.split("|"))
extraparamts=list()
for param in params:
if "ts=" in param:
extraparamts.append(param[3:-1])
print(extraparamts)
to list:
['1625090429']
['1625090489']
['1625090549']
['1625090599']
['1625090599']
and I want to print it in output without bracket and commas and in separate lines, like this:
1625090429
1625090489
1625090549
1625090599
1625090599
just to make it easier to sort and compare with same, but not sort file. Unfortunately it seems that
print(*tslist, sep=",")
does not work for me. Can you please tell me what am I doing wrong? I have tried itertools and
Upvotes: 1
Views: 774
Reputation:
Editing answer as per your edits , have added regex
import re
extraparamts = []
with open(inputt, "r") as f1:
f1 = f1.read()
for line in f1.splitlines(): # you can ignore splitlines if your data does not require it
if "ts" in line:
matches = re.findall("ts.*", line)
extraparamts.append(str(matches)[5:-5])
for data in extraparamts:
print(data)
Will Give
1625090
1625090
1625090
1625090
1625090
Upvotes: 0
Reputation: 410
Try this:
list = ['1625090429','1625090489','1625090549','1625090599','1625090599']
for item in list:
print(item)
Output:
1625090429
1625090489
1625090549
1625090599
1625090599
Try this:
list = [['1625090429'],['1625090489'],['1625090549'],['1625090599'],['1625090599']]
for item in list:
for x in item:
print(x)
Output:
1625090429
1625090489
1625090549
1625090599
1625090599
Upvotes: 1