Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.msdos.batch    |    Fun with MS-DOS batch files    |    42,547 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 42,116 of 42,547    |
|    Herbert Kleebauer to Andy Burnelli    |
|    Re: How to insert contents of a file (or    |
|    19 Dec 22 22:51:08    |
   
   XPost: alt.comp.os.windows-10, alt.comp.microsoft.windows   
   From: klee@unibwm.de   
      
   On 19.12.2022 08:43, Andy Burnelli wrote:   
   >   
   > How can one most easily insert contents of a file (or a line of text)   
   > at a given line-number location inside each of hundreds of text files?   
   >   
      
   > If I were to simply append the line to the _end_ of the *.ovpn files,   
   > instead of inserting thatline at line 103, I could use a Windows command   
   > line foreach loop to append the "include.txt" file to the *.ovpn file:   
   > for %f in (*.ovpn) do type include.txt >> %f   
   > But how can I _insert+ that one-line include.txt file at line 103?   
      
   If there are no poisoned characters (^%!) in the file you can use:   
      
   @echo off   
   setlocal enabledelayedexpansion   
   if exist out.txt del out.txt   
      
   set /a n=0   
      
   for /f "tokens=1,* delims=]" %%i in ('find /n /v "" ^< "in.txt"') do (   
    echo.%%j>>out.txt   
    set /a n=n+1   
    if !n!==103 echo vpn_user>>out.txt   
    if !n!==103 echo vpn_pass>>out.txt)   
      
   --- 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