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

  • Home
  • SEARCH
  • 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 9199529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:33:13+00:00 2026-06-17T22:33:13+00:00

The following code works pretty well printing the paragraph @echo off setlocal disableDelayedExpansion set

  • 0

The following code works pretty well printing the paragraph

@echo off
setlocal disableDelayedExpansion
set "skip="
for /f "delims=:" %%N in (
  'findstr /x /n ":::BeginText" "%~f0"'
) do if not defined skip set skip=%%N
>test.txt (
  for /f "skip=%skip% tokens=*" %%A in (
   'findstr /n "^" "%~f0"'
  ) do (
    set "line=%%A"
    setlocal enableDelayedExpansion
    echo(!line:*:=!
    endlocal
  )
)
type test.txt
exit /b

:::BeginText
This text will be exactly preserved with the following limitations:

  1) Each line will be terminated by CR LF even if original has only LF.

  2) Lines are limited in length to approximately 8191 bytes.

Special characters like ^ & < > | etc. do not cause a problem.
Empty lines are preserved!
;Lines beginning with ; are preserved.
:::Leading : are preserved

Is there a way to add a text marker like :::Endtext so that only the paragraph between
:::BeginText and :::Endtext is printed.

  • 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-06-17T22:33:14+00:00Added an answer on June 17, 2026 at 10:33 pm

    Sure 🙂

    And you can embed multiple named paragraphs within your script and selectively write them by using a unique label for each.

    The named text can appear anywhere within the script as long as GOTO and/or EXIT /B prevent the text from being executed.

    The script below encapsulates the logic in a :printParagraph routine for convenience.

    @echo off
    setlocal disableDelayedExpansion
    goto :start
    
    :::BeginText1
    Paragraph 1
      is preserved
    
    Bye!
    :::EndText
    
    :start
    echo Print paragraph 1 directly to screen
    echo ------------------------------------------
    call :printParagraph 1
    echo ------------------------------------------
    echo(
    echo(
    
    call :printParagraph 2 >test.txt
    echo Write paragraph 2 to a file and type file
    echo ------------------------------------------
    type test.txt
    echo ------------------------------------------
    echo(
    echo(
    
    echo Print paragraph 3 directly to screen
    echo ------------------------------------------
    call :printParagraph 3
    echo ------------------------------------------
    echo(
    echo(
    
    exit /b
    
    :::BeginText2
    This is paragraph 2
    
    Pure poetry
    :::EndText
    
    :printParagraph
    set "skip="
    for /f "delims=:" %%N in (
      'findstr /x /n ":::BeginText%~1" "%~f0"'
    ) do if not defined skip set skip=%%N
    set "end="
    for /f "delims=:" %%N in (
      'findstr /x /n ":::EndText" "%~f0"'
    ) do if %%N gtr %skip% if not defined end set end=%%N
    for /f "skip=%skip% tokens=*" %%A in (
     'findstr /n "^" "%~f0"'
    ) do (
      for /f "delims=:" %%N in ("%%A") do if %%N geq %end% exit /b
      set "line=%%A"
      setlocal enableDelayedExpansion
      echo(!line:*:=!
      endlocal
    )
    exit /b
    
    :::BeginText3
    One more...
    
      ...for good measure
    :::EndText
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following code is a pretty simple and complete JQuery Dialog. Everything works. Problem is
The following code works in all browser but IE8 and below. // Create Paragraph
We're using iText to generate PDF files from Java code, which works pretty well
I have the following code that runs a stored procedure repeatedly. It works pretty
The following code works fine on Linux but throws an exception on OS X
The following code works fine in firefox but as with many other things, I
The following code works fine: person = {:a=>:A, :b=>:B, :c=>:C} berson = {:a=>:A1, :b=>:B1,
The following code works as expected on CentOS and Ubuntu O/s but not on
The following code works, but I can't figure out what's going on memory-wise. Where
The following code works fine for Visual C++ 2008. However, when comes to Visual

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.