home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch.nt      Fun with Windows NT batch files      68,980 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 67,393 of 68,980   
   Herbert Kleebauer to Petr Laznovsky   
   Re: CRLF inside a XML data   
   18 Apr 19 18:32:15   
   
   From: klee@unibwm.de   
      
   On 18.04.2019 13:12, Petr Laznovsky wrote:   
      
   > So have XML parser output with following   
   > lines:   
   >   
   > text1#text2text3#text4text5#text6   
   >   
   > need to get avery "textX" into single variable.   
      
   Just write a small program in your preferred programming   
   language. But if you really want to do it with a batch,   
   here an example which converts an input file (a.txt)   
   with the above content to an output file (b.txt) with   
   each textX on a separate line which then you can process   
   with "for /f":   
      
      
   @echo off   
   setlocal enabledelayedexpansion   
      
   set infile=a.txt   
   set outfile=b.txt   
   set tmp0=_tmp0.tmp   
      
   if exist %tmp0% del %tmp0%   
      
   call :fopen %infile%   
   echo %infile% opened as input file   
      
   set n=0   
      
   :l1   
   call :getc_hex char %n%   
   set /a n=n+1   
      
   if %char%==-1 goto :l3   
   if %char%==0d goto :l1   
   if %char%==0a goto :l2   
   if %char%==23 goto :l2   
      
   echo !char!>>%tmp0%   
   goto :l1   
      
   :l2   
   echo 0d 0a>>%tmp0%   
   goto :l1   
      
      
   :l3   
   :: convert hexfile tmp0 to binary outfile   
   certutil -f -decodehex %tmp0% %outfile% >nul   
   if exist %tmp0% del %tmp0%   
      
   call :fclose   
      
   goto :eof   
      
      
   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
   :fopen   
   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
   set tmp1=_tmp1.tmp   
   set tmp2=_tmp2.tmp   
   set fsize=%~z1   
   set cache=-1   
   certutil  -f -encodehex %1 %tmp1% 4 >nul   
   set n=0   
   if exist %tmp2% del %tmp2%   
      
   for /f "tokens=1-16" %%a in (%tmp1%) do (   
     set /p =%%a%%b%%c%%d%%e%%f%%g%%h%%i%%j%%k%%l%%m%%n%%o%%p>%tmp2%   
     set /a n=n+1   
     if !n!==64 echo.>>%tmp2% & set n=0)   
      
   goto :eof   
      
   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
   :fclose   
   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
   del %tmp1%   
   del %tmp2%   
   goto :eof   
      
      
   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
   :getc_hex   
   :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::   
   if %2 GEQ %fsize% set /a %1=-1 & goto :eof   
   set /a i=%2/1024 & set /a j=2*(%2%%1024)   
   if %i%==%cache% goto :skip   
   echo                                       read cache line %i%   
   set cache=%i%   
   set skip=   
   if %i% GEQ 1 set skip="skip=%i%"   
   for /f %skip% %%i in (%tmp2%) do (   
      set line=%%i & goto :skip)   
   :skip   
   call set %1=%%line:~%j%,2%%   
   goto :eof   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca