Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7051561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:16:41+00:00 2026-05-28T03:16:41+00:00

This DOS batch script is stripping out the blank lines and not showing the

  • 0

This DOS batch script is stripping out the blank lines and not showing the blank lines in the file even though I am using the TYPE.exe command to convert the file to make sure the file is ASCII so that the FIND command is compatible with the file. Can anyone tell me how to make this script include blank lines?

@ECHO off
FOR /F "USEBACKQ tokens=*" %%A IN (`TYPE.exe "build.properties" ^| FIND.exe /V ""`) DO (
  ECHO --%%A--
)
pause
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:16:42+00:00Added an answer on May 28, 2026 at 3:16 am

    That is the designed behavior of FOR /F – it never returns blank lines. The work around is to use FIND or FINDSTR to prefix the line with the line number. If you can guarantee no lines start with the line number delimiter, then you simply set the appropriate delimiter and keep tokens 1* but use only the 2nd token.

    ::preserve blank lines using FIND, assume no line starts with ]
    ::long lines are truncated
    for /f "tokens=1* delims=]" %%A in ('type "file.txt" ^| find /n /v ""') do echo %%B
    
    ::preserve blank lines using FINDSTR, assume no line starts with :
    ::long lines > 8191 bytes are lost
    for /f "tokens=1* delims=:" %%A in ('type "file.txt" ^| findstr /n "^"') do echo %%B
    
    ::FINDSTR variant that preserves long lines
    type "file.txt" > "file.txt.tmp"
    for /f "tokens=1* delims=:" %%A in ('findstr /n "^" "file.txt.tmp"') do echo %%B
    del "file.txt.tmp"
    

    I prefer FINDSTR – it is more reliable. For example, FIND can truncate long lines – FINDSTR does not as long as it reads directly from a file. FINDSTR does drop long lines when reading from stdin via pipe or redirection.

    If the file may contain lines that start with the delimiter, then you need to preserve the entire line with the line number prefix, and then use search and replace to remove the line prefix. You probably want delayed expansion off when transferring the %%A to an environment variable, otherwise any ! will be corrupted. But later within the loop you need delayed expansion to do the search and replace.

    ::preserve blank lines using FIND, even if a line may start with ]
    ::long lines are truncated
    for /f "delims=" %%A in ('type "file.txt" ^| find /n /v ""') do (
      set "ln=%%A"
      setlocal enableDelayedExpansion
      set "ln=!ln:*]=!"
      echo(!ln!
      endlocal
    )
    
    ::preserve blank lines using FINDSTR, even if a line may start with :
    ::long lines >8191 bytes are truncated
    for /f "delims=*" %%A in ('type "file.txt" ^| findstr /n "^"') do (
      set "ln=%%A"
      setlocal enableDelayedExpansion
      set "ln=!ln:*:=!"
      echo(!ln!
      endlocal
    )
    
    ::FINDSTR variant that preserves long lines
    type "file.txt" >"file.txt.tmp"
    for /f "delims=*" %%A in ('findstr /n "^" "file.txt.tmp"') do (
      set "ln=%%A"
      setlocal enableDelayedExpansion
      set "ln=!ln:*:=!"
      echo(!ln!
      endlocal
    )
    del "file.txt.tmp"
    

    If you don’t need to worry about converting the file to ASCII, then it is more efficient to drop the pipe and let FIND or FINDSTR open the file specified as an argument, or via redirection.

    There is another work around that completely bypasses FOR /F during the read process. It looks odd, but it is more efficient. There are no restrictions with using delayed expansion, but unfortunately it has other limitations.

    1) lines must be terminated by <CR><LF> (this will not be a problem if you do the TYPE file conversion)

    2) lines must be <= 1021 bytes long (disregarding the <CR><LF>)

    3) any trailing control characters are stripped from each line.

    4) it must read from a file – you can’t use a pipe. So in your case you will need to use a temp file to do your to ASCII conversion.

    setlocal enableDelayedExpansion
    type "file.txt">"file.txt.tmp"
    for /f %%N in ('find /c /v "" ^<"file.txt.tmp"') do set cnt=%%N
    <"file.txt.tmp" (
      for /l %%N in (1 1 %cnt%) do(
        set "ln="
        set /p "ln="
        echo(!ln!
      )
    )
    del "file.txt.tmp"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help to prepare batch script on DOS. This script should run in following
I have written huge MS DOS Batch file. To test this batch file I
If I type this line in an MS-DOS command prompt window: ipy -X:ColorfulConsole IronPython
What's the fastest way using either DOS scripting or PowerShell to run this simple
First some background. I have a batch-type java process run from a DOS batch
I have a sh/bash script that needs to call a batch file with parameters
HI i want to implement this C code in batch file int i; scanf(%d,
I have a home-grown automated build script in the form of a DOS batch
The following DOS script snippet has a bug: if not exist %MyFolder% ( mkdir
Duplicate data removal using Perl called within via a batch file within Windows A

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.