MS DOS edit the file
4 answers
I just solve it myself. It will only search for var on line 2.
@echo OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
SET filename=%1
set LINENO=0
for /F "delims=" %%l in (%filename%) do (
SET /A LINENO=!LINENO!+1
IF "!LINENO!"=="2" ( call echo %%l ) ELSE ( echo %%l )
)
But I prefer to use cscript (vbscript or even jscript).
+1
source to share
It would be ugly if done with scripts with the original package. I would either
-
Do it in VBScript. If you really need it in a batch file, you can call the VBScript file from within the batch script. You can even pass% var% as an argument to VBScript.
-
Use a sed script. There are Unix command window ports such as GnuWin32 , GNU Utilities for Win32 (which I use), or Cygwin .
0
source to share
I would create a script that:
- scan input file
- write to second output file
- delete entry
- rename output
As far as dos commands for parsing are concerned, I did Google Search and came up with a good starting point:
@echo off
setlocal enabledelayedexpansion
set file=c:\file.txt
set output=output.txt
set maxlines=5000
set count=0
for /F "tokens=* usebackq" %%G in ("%file%") do (
if !count!==%maxlines% goto :eof
set line=%%G
set line=!line:*000000000000=--FOUND--!
if "!line:~0,9!"=="--FOUND--" (
echo %%G>>"%output%"
set /a count+=1
)
)
(stolen from Intarwebnet)
-2
source to share