<http://www.netikka.net/tsneti/info/tscmd025.htm>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Mon 29-Dec-2014 11:45:48

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.

" "

25} How can I quote with e.g. "> " an entire message?

Assume the following LFN-type test file: "My test file.txt"
line 1
line 2 &()[]{}^=;!'+,`~
line 3 <>
line 4 ""

line 6 Line 5 is empty!
line 7
line 8 &()[]{}^=;!'+,`~
line 9

A third party solution is to use G(nu)AWK or SED. With G(nu)AWK
  @echo off & setlocal enableextensions
  set myfile_=My test file.txt
  for /f "tokens=* delims=" %%f in ("%myfile_%") do (
    set myfile_=%%~sf)
  gawk '{printf "> %%s\n",$0}' "%myfile_%"
  endlocal & goto :EOF

The output is
  C:\_D\TEST>cmdfaq
  > line 1
  > line 2 &()[]{}^=;!'+,`~
  > line 3 &lt;&gt;
  > line 4 ""
  >
  > line 6 Line 5 is empty!
  > line 7
  > line 8 &()[]{}^=;!'+,`~
  > line 9
The renaming to a SFN-format (%%~sf) is needed when the G(nu)AWK or SED versions originally assumed in this FAQ are used.
But the output could also be
  C:\_D\TEST>cmdfaq
This version of GAWK.EXE is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need a x86 (32-bit) or x64 (64-bit) version of the program

  @echo off & setlocal enableextensions
  rem With GnuWin32 (let's call it unxgawk)
  rem Needed when run on e.g. 64-bit Windows 7/8

  set myfile_=My test file.txt
  unxgawk "{printf \"^> %%s\n\",$0}" "%myfile_%"
  endlocal & goto :EOF

With SED
  @echo off & setlocal enableextensions
  set myfile_=My test file.txt
  for /f "tokens=* delims=" %%f in ("%myfile_%") do (
    set myfile_=%%~sf)
  sed -e "s/^/> /" "%myfile_%"
  endlocal & goto :EOF

Again, the output is
  C:\_D\TEST>cmdfaq
  > line 1
  > line 2 &()[]{}^=;!'+,`~
  > line 3 &lt;&gt;
  > line 4 ""
  >
  > line 6 Line 5 is empty!
  > line 7
  > line 8 &()[]{}^=;!'+,`~
  > line 9

A Visual Basic aided command line script solution also applies (and gives exatcly the same output).
  @echo off & setlocal enableextensions
  ::
  :: Your message file

  set myfile_=My test file.txt
  ::
  :: Build a Visual Basic Script

  set vbs_=%temp%\tmp$$$.vbs
  set skip=
  findstr "'%skip%VBS" "%~f0" > "%vbs_%"
  ::
  :: Run it with Microsoft Windows Script Host Version 5.6

  cscript //nologo "%vbs_%" "> " < "%myfile_%"
  ::
  :: Clean up

  for %%f in ("%vbs_%") do if exist %%f del %%f
  endlocal & goto :EOF
  '
  '............................................
  'The Visual Basic Script
  '

  set n = WScript.Arguments 'VBS
  quoteStr = n(0) 'VBS
  Do While Not WScript.StdIn.AtEndOfStream 'VBS
    str = WScript.StdIn.ReadLine 'VBS
    WScript.StdOut.WriteLine quoteStr & str 'VBS
  Loop 'VBS

The output is
  C:\_D\TEST>cmdfaq
  > line 1
  > line 2 &()[]{}^=;!'+,`~
  > line 3 &lt;&gt;
  > line 4 ""
  >
  > line 6 Line 5 is empty!
  > line 7
  > line 8 &()[]{}^=;!'+,`~
  > line 9

The VBS-part in the above could also be abbreviated as
  '
  '............................................
  'The Visual Basic Script
  '

  Do While Not WScript.StdIn.AtEndOfStream 'VBS
    WScript.StdOut.WriteLine WScript.Arguments.Unnamed(0) & WScript.StdIn.ReadLine 'VBS
  Loop 'VBS

How about a pure script?
  @echo off & setlocal enableextensions disabledelayedexpansion
  ::
  :: Your parameters
  set myfile_=My test file.txt
  ::
  :: Use "> " as the quote character
  for /f "tokens=* delims=" %%r in ('type "%myfile_%"') do (
    echo ^> %%r)
  endlocal & goto :EOF

The output is
  > line 1
  > line 2 &()[]{}^=;!'+,`~
  > line 3 <>
  > line 4 ""
  > line 6 Line 5 is empty!
  > line 7
  > line 8 &()[]{}^=;!'+,`~
  > line 9
Note the difference. Line five, that is the empty line is skipped by the pure script.