Page 1 of 1
reading a TEXT file and i need to bring a structure into it
Posted: 26 Dec 2021 09:19
by nnnmmm
WEB.BAT has
Code: Select all
@ECHO OFF
SET K1=M:\WEB.TXT
SET DS1=7
SET DS2=75
SetLocal EnableExtensions EnableDelayedExpansion
SET CC=0
FOR /F "DELIMS=" %%V IN ('TYPE "%K1%"') DO (
SET /A CC=!CC!+1
IF !CC! GEQ 1 IF !CC! LEQ 9 SET DD= !CC!
IF !CC! GTR 9 SET DD=!CC!
SET "VV=%%V"
REM SET "VV=!VV:&=^&!"
ECHO !DD! !VV:~%DS1%,%DS2%!
IF !CC! EQU 35 GOTO SCREEN_FULL
)
:SCREEN_FULL
PAUSE
WEB.TXT has
http://www.zt!w3.com/forum/forum.php
http://truebasic.com/forum
http://www.google.com/advanced_search?n ... =&ie=UTF-8
https://www.dict.cc/?s=Matrose!
http://www.ho!!!!!!!!!!!!!!!t-keyboard.com/
http://www.mscd.edu/~mdl/gerresources/A.htm
web.bat displays & but not "!"
how can i make it display "!"?
putting this &=^& corrupts website with ^&
can this be done internally?
Re: reading a TEXT file and i need to bring a structure into it
Posted: 27 Dec 2021 07:04
by aGerman
First, it seems that you want to cut off the protocol specifier. HTTP and HTTPS have different lengths. So, your DS1 of 7 doesn't make sense. Taking a backslash as delimiter is more suitable.
As to your problem: You define variable VV with delayed expansion enabled. That won't work.
Code: Select all
@echo off &setlocal EnableExtensions DisableDelayedExpansion
for /f "tokens=1,2* delims=:/" %%i in ('type "web.txt"^|findstr /n "^"') do (
set "line= %%i"
set "address=%%k"
setlocal EnableDelayedExpansion
echo !line:~-2! !address!
endlocal
if %%i equ 35 goto SCREEN_FULL
)
:SCREEN_FULL
pause
Steffen
Re: reading a TEXT file and i need to bring a structure into it
Posted: 28 Dec 2021 04:46
by nnnmmm
i couldnt bring a structure in your code for me to use it or upgrade it further
Code: Select all
@ECHO OFF
setlocal EnableExtensions DisableDelayedExpansion
SET K1=M:\WEB.TXT
SET DS1=0
SET DS2=35
SET CC=0
FOR /F "tokens=*" %%V in ('TYPE "%K1%"') DO (
setlocal DisableDelayedExpansion
set "VV=%%V"
setlocal EnableDelayedExpansion
SET /A CC=!CC!+1
IF !CC! GEQ 1 IF !CC! LEQ 9 SET DD=0!CC!
IF !CC! GTR 9 SET DD=!CC!
IF !CC!==3 (ECHO !DD! pass
) ELSE (
SetLocal EnableDelayedExpansion
ECHO !DD! !VV:~%DS1%,%DS2%!
EndLocal
)
IF !CC! EQU 35 GOTO :SCREEN_FULL
)
:SCREEN_FULL
ECHO.
PAUSE
if WEB.TXT has more than 15 items in the list, it fails and says maximum setlocal RECURSION level reached,
windows batch commands have many unfathomable operators but they have no structures whatsoever, even for a code as simple as the above, i will try using CALL from an external file. i did this way once and kind of worked (at least 1st test drive). you may be right "cant be done" internally. i'd like to ask again when my external batch is ready, thanks for the help
Re: reading a TEXT file and i need to bring a structure into it
Posted: 28 Dec 2021 05:34
by aGerman
Think about the following:
- delayed expansion is disabled at the beginning, thus it is disabled at the beginning of your loop already
- incrementing the number works always using SET /A "CC+=1" and doesn't need delayed expansion enabled
- only outputting or working with updated values needs enabled delayed expansion
- every SETLOCAL without ENDLOCAL in the body of your loop will lead to the maximum recursion error earlier or later.
- once you leave a subenvironment using ENDLOCAL, the previous expansion state is restored
Steffen
Re: reading a TEXT file and i need to bring a structure into it
Posted: 28 Dec 2021 11:16
by Aacini
Excuse me, but I don't understand what "bring a structure into a text file" means. Is this your input data file?
Code: Select all
http://www.zt!w3.com/forum/forum.php
http://truebasic.com/forum
http://www.google.com/advanced_search?n ... =&ie=UTF-8
https://www.dict.cc/?s=Matrose!
http://www.ho!!!!!!!!!!!!!!!t-keyboard.com/
http://www.mscd.edu/~mdl/gerresources/A.htm
If so, why don't you post what is the desired output given such an input? In this way, we could help you to get such result. By the way, this is the
standard method to request help...
Antonio
Re: reading a TEXT file and i need to bring a structure into it
Posted: 28 Dec 2021 13:17
by Squashman
The code given to you by aGerman certainly looks like it solves your problem. I am not sure why you have not attempted to use his code. All you did was update your code with what you thought might be a new solution.
Re: reading a TEXT file and i need to bring a structure into it
Posted: 06 Jan 2022 11:25
by nnnmmm
>> SET /A "CC+=1"
i will try this way now. i dont know C compiler, i know fortran and true basic, and some pascal (but much was forgotten)
i have limited knowledge of DOS commands, especailly DOS operators.
>> bring a structure into it
i meant this way by being able to put IF statement inside so that i could handle and filter things.
i need to feed unimaginably long registries, i dont need to see all string lengths, but if i can chop and view overall somewhere maybe like [20:100] or [40: 120] string regions to identify some key words inside, then i can link that registry to nircmdc.exe to find it. such is also the case with long website addresses. i will link this kind of batches with ztree file manager.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
HKEY_USERS\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
HKEY_USERS\S-1-5-21-790525478-796845957-725345543-1003\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\Favorites\
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace
i will get back to you hopefully in few days, thanks for the help