I have a batch file that reads in a line of text that I can escape however is necessary.
I need to deploy this file to a small user base, so installing sed on everyone's PC isn't an option.
So I've been trying to do this with a batch file.
Input:
TAG1 GRfoo XY ^(as generated by Boolean^) minimum enclosed area ^(um2^) ^> ^= 0.10
... that input is eventually parsed in this line of code:
for /f "usebackq tokens=2*" %%i in (`echo %*`) DO (
... where %* is the argument passed through a CALL: call:retTokenThreePlus !tagline!
I have tried seemingly every combination of escaping the >: ^> ^^^>, ^^^^^>, etc. Etc.
I can't seem to figure out how to not have the > disappear from what is passed to the :retTokenThreePlus method.
Thanks!
Batch file relevant code:
IF "%3"=="" (
  :: This monstrosity sets tagline to the FINDSTR result.
  for /f "usebackq tokens=*" %%a in (`FINDSTR /C:"TAG%2 " %tagfile%`) do set tagline=%%a
  call:retTokenTwo !tagline!
  set tagrule=!token!
  echo !tagline!
  call:retTokenThreePlus !tagline!
  set CMDLINE=!CMDLINE! !tagrule! !token!
  goto :write
)
:: Method to return only the second token of the parm list passed to it
:retTokenTwo
  set token=%2
  echo TOKEN2 %token%
  goto :eof
:: Method to return tokens 3+ of the parm list passed to it
:retTokenThreePlus
  REM setlocal enabledelayedexpansion
  for /f "usebackq tokens=2*" %%i in (`echo %*`) DO (
    set "token=%%j"
  )
  REM echo TOKEN3 !token!
  goto :eof
Output with echo on:
C:\gf28hpp\layout\icwinlp>set CMDLINE=$ 
C:\gf28hpp\layout\icwinlp>set token="" 
C:\gf28hpp\layout\icwinlp>IF "" == "" (
for /F "usebackq tokens=*" %a in (`FINDSTR /C:"TAG1 " block_checkdrc.tags`) do set tagline=%a  
 call:retTokenTwo !tagline!  
 set tagrule=!token!  
 echo !tagline!  
 call:retTokenThreePlus !!tagline!!  
 set CMDLINE=!CMDLINE! !tagrule! !token!  
 goto :write 
)  ELSE (
 ...[redacted]... 
) )  
) 
C:\gf28hpp\layout\icwinlp>set tagline=TAG1 GRfoo XY ^(as generated by Boolean^) minimum enclosed area ^(um2^) ^> ^= 0.10 
C:\gf28hpp\layout\icwinlp>set token=GRfoo 
C:\gf28hpp\layout\icwinlp>echo TOKEN2 GRfoo 
TOKEN2 GRfoo
C:\gf28hpp\layout\icwinlp>goto :eof 
TAG1 GRfoo XY ^(as generated by Boolean^) minimum enclosed area ^(um2^) ^> ^= 0.10
C:\gf28hpp\layout\icwinlp>REM setlocal enabledelayedexpansion 
C:\gf28hpp\layout\icwinlp>for /F "usebackq tokens=2*" %i in (`echo TAG1 GRfoo XY (as generated by Boolean) minimum enclosed area (um2) `) DO (set "token=%j" ) 
C:\gf28hpp\layout\icwinlp>(set "token=XY (as generated by Boolean) minimum enclosed area (um2) " ) 
C:\gf28hpp\layout\icwinlp>REM echo TOKEN3 !token! 
C:\gf28hpp\layout\icwinlp>goto :eof