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 68,391 of 68,980    |
|    JJ to All    |
|    Re: Replace line in a txt file with miss    |
|    08 Jan 24 12:03:59    |
   
   From: jj4public@outlook.com   
      
   On Sun, 7 Jan 2024 21:44:44 -0500, Zaidy036 wrote:   
   > Windows 10 Pro   
   >   
   > My sample.txt is similar to the following up to 50 lines:   
   > SSID 1 : Residents 5   
   > SSID 2 : HSL2   
   > SSID 3 : AscomI62   
   > SSID 4 : Guest   
   > SSID 5 : ResidentsA   
   > SSID 6 : ResidentsB   
   > SSID 7 :   
   > SSID 8 : XFINITY   
   > SSID 9 : A440   
   >   
   > "FOR /D %%S IN ..." then scans sample.txt for specific names to make   
   > result.txt.   
   > --PROBLEM: If a line has nothing after "SSID nn :" then my batch exits.   
   >   
   > The sequence of numbers must be complete and I have tried many ways but   
   > failed to replace any random line without an "SSID nn :" entry with   
   > "SSID nn : None".   
   >   
   > Any suggestions?   
      
   Can't fix code if you don't provide it.   
      
   Chances are that, you're not double quoting a variable when needed. So, when   
   the variable content has space(s) in it, the space(s) in the expanded string   
   will be treated as a command line argument separator.   
      
   The file should be done like this.   
      
   @echo off   
   setlocal enabledelayedexpansion   
   set "input=source.txt"   
   set "output=result.txt"   
   >"%output%" (   
    for /f "usebackq tokens=1,2* delims=:" %%A in ("%input%") do (   
    rem check for empty/white-spaces string   
    2>nul set /a "x=1*%%B1"   
    if !x! == 0 (   
    rem not empty or only has white-spaces   
    echo %%A:%%B   
    ) else echo %%A: None   
    )   
   )   
      
   --- 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