Page 1 of 1

Best way to insert/remove line in text file?

Posted: 02 Aug 2009 22:30
by Billy885
Hello all,

Have learned a lot here and thanks for that!

I have a problem that I dont have my head into yet and hoping you all can help me.

Need to use batch file commands here and I need insert a line of text and then later remove that line depending on what the operator wants.

Code showing sample of the text file.

Code: Select all

[MAIN]
  MAP Netmountains/load.ini
  TIME 12.0
  TIMECONSTANT 1
  CloudType 0
  CloudHeight 1500.0
.......
.......
can be 200 lines at least
The line in question appears most of the time on line 4 of the code (TIMECONSTANT 1), but not always. Any ideas here would be greatly appreciated and thanks in advance!

Posted: 03 Aug 2009 06:41
by ghostmachine4
you can use vbscript,
1) to remove the TIMECONSTANT line

Code: Select all

Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "c:\test\file.txt"
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfStream
   strLine = objFile.ReadLine
   If InStr(strLine,"TIMECONSTANT") < 1 Then
      WScript.Echo strLine
   End If
Loop
objFile.Close