Sep-09-2017, 04:03 AM
The following text is a small part of a large (4MB) file that I am trying pull text
from and save it to a csv file to open in Excel.
<Tag Name="C0000" TagType="Base" DataType="DINT" Radix="Decimal" Constant="false" ExternalAccess="Read/Write">
<Description>
<![CDATA[System
Signals]]>
</Description>
<Comments>
<Comment Operand=".0">
<![CDATA[System
Always OFF
Bit]]>
</Comment>
<Comment Operand=".1">
<![CDATA[System
Always ON
Bit]]>
</Comment>
<Comment Operand=".2">
<![CDATA[System
Simulation State]]>
</Comment>
...etc.
The bold face chars are what I want to put together into another file.
The .0, .1, .2 etc goes on to a max of .31 but can end before that.
The Tag Name "C0000" is just text and usually a descriptive name.
After .31 or what ever another Tag Name (ie. "C0001", "Timer", etc) and then we do it again 0 to 31.
So far I've got a beginning but I am now struggling.
The forum states to give as much info as possible I hope I have done this.
I'm using python2.7 on a pc.
Thanks for reading to the end.
And thanks for any help.
from and save it to a csv file to open in Excel.
<Tag Name="C0000" TagType="Base" DataType="DINT" Radix="Decimal" Constant="false" ExternalAccess="Read/Write">
<Description>
<![CDATA[System
Signals]]>
</Description>
<Comments>
<Comment Operand=".0">
<![CDATA[System
Always OFF
Bit]]>
</Comment>
<Comment Operand=".1">
<![CDATA[System
Always ON
Bit]]>
</Comment>
<Comment Operand=".2">
<![CDATA[System
Simulation State]]>
</Comment>
...etc.
The bold face chars are what I want to put together into another file.
The .0, .1, .2 etc goes on to a max of .31 but can end before that.
The Tag Name "C0000" is just text and usually a descriptive name.
After .31 or what ever another Tag Name (ie. "C0001", "Timer", etc) and then we do it again 0 to 31.
So far I've got a beginning but I am now struggling.

#open file to read with open('E:\\ab-test.txt') as fo: #read a line for x in fo.read().split("\n"): #if we find 'Tag Name' get what follows if (re.findall('Tag Name',x)): print x[11:16], #now look for CDATA and get text up to ] if (re.findall('CDATA',x)): print x[9:] fo.close()
Output:C0000 System
System
.
.
System
What I want is to have the output look like the following:Output:C0000 System Signals
C0000.0 , System Always OFF Bit
C0000.1 , System Always ON Bit
C0000.2 , System Simulation State
Once I have the output done it will be saved to newfile.csv The forum states to give as much info as possible I hope I have done this.
I'm using python2.7 on a pc.
Thanks for reading to the end.
And thanks for any help.