Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students explore these related Databases questions

Question

2. How will the team select a leader?

Answered: 3 weeks ago