Get value from a Text File and store that value in another Text file

(imported topic written by Techadmin)

Hi,

Below is the code, i want to get the ip address from the below code(6th line) in one text file and store it in another text file…

File 1: (Get Ip address from 6th line here)

<PROPERTY propname=“host”

              propvalue="Treats"/>

<PROPERTY propname=“port”

              propvalue="10"/>

<PROPERTY propname=“host”

              propvalue="172,23,34,45"/>

<PROPERTY propname=“port”

              propvalue="123"/>

<PROPERTY propname=“host”

              propvalue="172,23,34.56"/>

<PROPERTY propname=“port”

              propvalue="435"/>

File 2: (I Have to store that ip address from file 1 in the 6th line inside propvalue.)

<PROPERTY propname=“host”

              propvalue=""/>

<PROPERTY propname=“port”

              propvalue=""/>

<PROPERTY propname=“host”

              propvalue=""/>

<PROPERTY propname=“port”

              propvalue=""/>

Can somebody help me on this please…

(imported comment written by gearoid)

Hi.

Assuming you’re just doing a straight replace of line 6 in file 2 with line 6 of file 1. Use this actionscript.

For windows new lines it’s got the cr/lf for line breaks.

delete createfile

createfile until _EOF_

// extract and output the first 5 lines of the second file adding crlf (windows new line) via hex codes to each line

{concatenation "%0d%0a" of lines whose (line number of it < 6) of "c:\temp\file2.txt"}

// extract the 6th line of the first file

{line 6 of "c:\temp\file1.txt"}

_EOF_

// replace the second file

delete "c:\temp\file2.txt"

move __creatfile "c:\temp\file2.txt"

Try the following in your fixlet debugger to find out more about the types

Q: properties of type “file”

Q: properties of type “file line”

A great place to explore inspectors is here:
http://support.bigfix.com/inspectorsearch/inspector_search.html

Garret

(imported comment written by Techadmin)

Thanks Garret for spending your time on this, The above code didn’t work out well…

I found another way of doing it.

(imported comment written by Tim.Rice)

And that way was … ???

It was through a third party tool not with relevance… But there are still some issues with this…
Can somebody plz help me on this with relevance code

Hi - let us know what’s not working out.
We’re happy to help you figure out why.

Pardon the lack of elegant nature of this… but I took the post and garret then modified it to meet the use case as I saw it.
Let me know if it works for your use…

// Enter your action script here
delete __createfile
// extract and output the first 4 lines of the second file adding crlf (windows new line) via hex codes to each line
// extract the 5th line of the first file
// extract the 6th - nth line of the first file

createfile until EOF
{concatenation “%0d%0a” of lines whose (line number of it < 5) of file “c:\temp\forum2.txt”}
{(“propvalue=%22” & it & “%22/>”)of concatenation “.” of substrings separated by “,” of substrings separated by “.” of substrings between “%22” of line 5 of file “c:\temp\forum1.txt”}
{concatenation “%0d%0a” of lines whose (line number of it > 5) of file “c:\temp\forum2.txt”}
EOF

// replace the second file

delete “c:\temp\forum2.txt”
copy __createfile “c:\temp\forum2.txt”

~jgo

@jgo

I will share the original scenario from the old forum.
Then lets work on sorting this out…

Thanks for spending your time on this issue…

It’s getting very tricky for me to figure out a solution…

EDIT: Check this link for the actual scenario

It looks like the original data is an XML document. In that case I would highly recommend using XML inspectors (unfortunately only available in Windows clients). Trying to parse XML any other way is very likely to fail in the future. Here’s an example:

q: lines of file "C:\Users\IBM_ADMIN\Desktop\xml.txt"
A: <root><PROPERTY propname="host" propvalue="Treats"/>
A: <PROPERTY propname="port" propvalue="10"/>
A: <PROPERTY propname="host" propvalue="172,23,34,45"/>
A: <PROPERTY propname="port" propvalue="123"/>
A: <PROPERTY propname="host" propvalue="172,23,34.56"/>
A: <PROPERTY propname="port" propvalue="435"/></root>
T: 0.501 ms

q: xml document of file "C:\Users\IBM_ADMIN\Desktop\xml.txt"
E: This expression evaluates to an unrepresentable object of type "xml dom document"
T: 0.604 ms

q: (it as text) of attribute "propvalue" of child node 5 of first child of xml document of file "C:\Users\IBM_ADMIN\Desktop\xml.txt"
A: 435
T: 0.614 ms

q: (it as text) of attribute "propvalue" of xpath "PROPERTY[6]" of first child of xml document of file "C:\Users\IBM_ADMIN\Desktop\xml.txt"
A: 435
T: 0.633 ms

@jeremylam

Thanks for working on this…
We are getting closer… now, how do you place the value in another xml doc?
Where can i find the XML inspector document?

1 Like

This is a classic problem in application engineering. Typically we call on something else to edit the xml for us at that point. We don’t tend to use actionscript for it.

I’ve seen folks use powershell and vbscript for this type of gig…

Here’s an example that you might find useful:
https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014881678

1 Like

Here is the same link within forum.bigfix.com

1 Like