Edit an existing text file

(imported topic written by rmnetops91)

I have tried the few posts I have found on editing an existing text file, but it doesn’t work in my case.

I need to add this new line:

tw.proxy.host=compname.domain.com

To the bottom of a text file that has this existing content:

  1. AGENT Properties
  2. The Properties in this section are unique to the “agent.properties” file.

space.bootstrapables=station

tw.agent.changeBlockSize=500

tw.agent.taskPriority=4

tw.rpc.exec.threadPoolSize=4

tw.agent.queueMax=10

sun.net.client.defaultReadTimeout=1200000

sun.net.client.defaultConnectTimeout=1200000

sun.rmi.transport.tcp.threadKeepAliveTime=5000

tw.server.host=compname2.domain.com

tw.server.port=9898

When I try the action script example here: http://forum.bigfix.com/viewtopic.php?id=3850

This is the output I get (It mashes the original file all togther, and then appends the new line at the bottom):

  1. AGENT Properties# The Properties in this section are unique to the “agent.properties” file.space.bootstrapables=stationtw.agent.changeBlockSize=500tw.agent.taskPriority=4tw.rpc.exec.threadPoolSize=4tw.agent.queueMax=10sun.net.client.defaultReadTimeout=1200000sun.net.client.defaultConnectTimeout=1200000sun.rmi.transport.tcp.threadKeepAliveTime=5000tw.server.host=compname2.domain.comtw.server.port=9898

tw.proxy.host=compname.domain.com

This breaks the application. I need to keep it in it’s original format, with the new line at the bottom.

Thanks

(imported comment written by SystemAdmin)

Here is one way to do it that should preserve your file structure.

delete __appendfile

delete update.bat

appendfile echo tw.proxy.host=compname.domain.com >> drive:path\agent.properties

copy __appendfile update.bat

wait update.bat

This approach works especially well when paired with relevance substitution. In my environment, I built and/or edit a lot of properties and ini files on the fly that are customized to the machine/location/brand/etc.

appendfile echo property = {substitution for some local attribute} >> app_setup.ini

(imported comment written by SystemAdmin)

rmnetops,

In that other example post, it was written as…

appendfile {concatenation of lines of file (parameter “filename”) & “%0d%0a” & “some new text” & “%0d%0a”}

I think you’re looking for something like…

appendfile {concatenation “%0d%0a” of lines of file (parameter “filename”) & “%0d%0a” & “some new text” & “%0d%0a”}

What’s happening is you’re reading the lines of a file and concatenating them together without a CRLF, which would be the separator. That’s probably why it got all jumbled together.

Paul

(imported comment written by rmnetops91)

Both methods work.

Thanks!

(imported comment written by SystemAdmin)

I made a minor correction above. I should have said contatenation “%0d%0a”. I always prefer CRLF, not LFCR.

Glad it worked.

-Paul