Simple Sorting

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dspKevlar
Posts: 1
Joined: 06 Sep 2013 10:41

Simple Sorting

#1 Post by dspKevlar » 06 Sep 2013 10:49

Hey all,
I have a simple .txt file and I have to grab data specific data from that file and simply place it into another .txt file. I can do this fine, but I am trying to tell it to stop reading at a blank line. i have no clue what the character is for this. There can also be multiple sections that I have to read throughout the file so I can't just have it terminate after a set number of times. This is my code.

Code: Select all

@echo off
setlocal EnableDelayedExpansion
set flag = "N"
for /f "tokens=*" %%a in (input.txt) do (
   if "%%a" == "" (
      set flag=N
   )
   if !flag!==Y  echo. %%a >> Test_Data.txt
   if "%%a" == "Start_Test" set flag=Y
        )
pause


Thanks for any and all help!

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Simple Sorting

#2 Post by aGerman » 06 Sep 2013 13:47

A FOR /F loop is skipping blank lines automatically.
Untested attempt:

Code: Select all

@echo off
setlocal EnableDelayedExpansion
set flag = "N"
for /f "tokens=*" %%a in ('findstr /n "^" "input.txt"') do (
   set "line=%%a"
   if "!line:*:=!"=="" (
      set flag=N
   )
   if !flag!==Y  echo. !line:*:=! >> Test_Data.txt
   if "!line:*:=!" == "Start_Test" set flag=Y
        )
pause

Regards
aGerman

Post Reply