how to process ALL lines of text in a file, including BLANKS
Posted: 21 Nov 2011 15:17
I need code to process each line of text held by INPUT.TXT and write it to OUTPUT.TXT
My first stage is to create OUTPUT.TXT the same as INPUT.TXT,
after which I can code appropriate tweaks in the output depending on the contents of each input line.
This is what I have so far
Right now I am stuck because the input includes blank lines, and the FOR loop excludes them.
I believe SET /P is able to deliver blank lines,
but I cannot see how to make SET /P iterate through each line of INPUT.TXT.
N.B. A plausible alternative is to accept that blank lines are not delivered.
and to deduce that there was one immediately before any line that starts "[" and ends "*]".
The final result will process an INI configuration file with many blocks of code such as
I will have greater confidence that a block has started with "[" and ends "*]" if I also detect the immediately preceeding blank line
Regards
Alan
My first stage is to create OUTPUT.TXT the same as INPUT.TXT,
after which I can code appropriate tweaks in the output depending on the contents of each input line.
This is what I have so far
Code: Select all
@echo off & setlocal EnableDelayedExpansion
IF EXIST OUTPUT.TXT DEL OUTPUT.TXT
SET /A N=1000
FOR /F "eol= tokens=1* delims=" %%d IN ('type INPUT.TXT') DO (
SET /A N+=1
ECHO %%d>> OUTPUT.TXT
)
Right now I am stuck because the input includes blank lines, and the FOR loop excludes them.
I believe SET /P is able to deliver blank lines,
but I cannot see how to make SET /P iterate through each line of INPUT.TXT.
N.B. A plausible alternative is to accept that blank lines are not delivered.
and to deduce that there was one immediately before any line that starts "[" and ends "*]".
The final result will process an INI configuration file with many blocks of code such as
Code: Select all
[NVIDIA Updates*]
LangSecRef=3021
DetectFile=%CommonAppData%\Nvidia\Updates
Default=False
FileKey1=%CommonAppData%\Nvidia\Updates|*.bak
[O&O Defrag*]
LangSecRef=3024
Detect=HKCU\Software\O&O\O&O Defrag
Default=False
FileKey1=%Documents%\O&O\O&O Defrag\data\reports|*.*|RECURSE
I will have greater confidence that a block has started with "[" and ends "*]" if I also detect the immediately preceeding blank line
Regards
Alan