Best way to insert/remove line in text file?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Billy885
Posts: 5
Joined: 01 Aug 2009 12:22

Best way to insert/remove line in text file?

#1 Post by Billy885 » 02 Aug 2009 22:30

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!

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

#2 Post by ghostmachine4 » 03 Aug 2009 06:41

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

Post Reply