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 68,399 of 68,980   
   Zaidy036 to All   
   Re: Replace line in a txt file with miss   
   08 Jan 24 13:15:54   
   
   From: Zaidy036@air.isp.spam   
      
   On 1/8/2024 12:03 AM, JJ wrote:   
   > 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   
   >    )   
   > )   
   Sorry, did not mean to cause further confusion.   
      
   _JJ (total entries in list) and _NN (multi-run counter) are set before   
      
   SET /A _X=0   
   :_RepeatX   
   SET /A _X=%_X% + 1   
   FOR /D %%S IN ("Guest" "Residents" "ResidentsA" "Residents 5") DO (   
   FINDSTR /C:"SSID %_X% : %%~S" F:\_%_NN%NetworkB.txt >> F:\_%_NN%NetworkL.txt   
   )   
   IF NOT %_X%==%_JJ% && GOTO _RepeatX   
      
   (removed "FOR /L" to simplify for test)   
      
   "usebackq tokens" is what I am missing so thanks for bringing to my   
   attention. I will learn about applying it for the above or for making   
   F:\_%_NN%NetworkB.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