i used this code to extracts all the content of every instance of the fields 'agents' and 'ir' appeared from the example given, and gives
i used this code to extracts all the content of every instance of the fields 'agents' and 'ir' appeared from the example given, and gives the output shown in example2 ,
import re x = "agent"
filename = "text.txt"
agent=[]
ir=[]
with open(filename, "rt") as in_file:
for line in in_file: line = line.translate(None, ',:""')
if x in line:
#print line[line.find(x)+len(x):]
agent.append((line[line.find(x)+len(x):]).strip())
import re
x="ir"
filename = "text.txt"
with open(filename, "rt") as in_file:
for line in in_file:
line = line.translate(None, ',:""')
if x in line:
#print line[line.find(x)+len(x):]
ir.append((line[line.find(x)+len(x):]).strip())
for i in range(1,len(agent)): print agent[i-1] + "," + ir[i-1]
example text
dgfh lsdkfh lskdjv 3w4534 "agent":"FIVR_VNN_STAP", fghj ddyj dryghdry "agent":"FIVR_VNN_STAP", dryjh fghxrt zaerg zdf "agent":"FIVR_IOCTRL_STAP", "ir":"RTDR_TAP0", "ir":"RTDR_TAP3", "ir":"RTDR_TAP4", JZDHA ASLDJ\ L ADLKFJ \LADJF ASD F\SDF \AF\DSFDFJKSDKFJLZRJF DLFKZG ERJOI AZEODFIH SLDIRF AO DFJLS S DLKFJ LAWER FSDLFJ LJRI FUZERJF SDJKF \EFJZ SDKJF ZS RF\;WEOJF ;ZSKDJF ;SKDJFLDKJF;SKJR ZSKFJG LZSDJF ZSDJF; J;SKDJF; ;SKDJ;FGZEJR;GODJF; G;ZSLKF;Z SF;G JZS;FJG ;SEORUF \LSDKFJ C\LSJD F\JSDFHK \GHKSDGFK \SJDGF A\
output:
FIVR_VNN_STAP,RTDR_TAP0
FIVR_VNN_STAP,RTDR_TAP3
FIVR_IOCTRL_STAP,RTDR_TAP4
FIVR_1P05_STAP,RTDR_TAP4
FIVR_1P05_STAP,RTDR_TAP
FIVR_1P05_STAP,RTDR_TAP0
How would i write this output to a CVS file?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started