A
A
Alexander2016-03-14 09:22:09
cmd/bat
Alexander, 2016-03-14 09:22:09

How to organize the search for words by the number of characters?

Good afternoon!
There are several folders that store txt files containing lists of domains. I wrote a bat file that loops through all files from a specific folder (dest=G:\Domains\BAT\Files\2008\) and searches for keywords in them from a txt file (G:\Domains\BAT\tags.txt) . Found domains are written to a new txt file, which is saved in the folder "G:\Domains\BAT\Results\2008"

echo on
setlocal EnableDelayedExpansion
>nul chcp 1251

set "dest=G:\Domains\BAT\Results\2008\"
set "dir=G:\Domains\BAT\Files\2008"

>nul chcp 866

(FOR /F "tokens=*" %%z in ('dir %dir% /b /a-d') do (

FOR /F "usebackq" %%i IN ("G:\Domains\BAT\tags.txt") do ( 
set word=%%i
FOR /F "tokens=*" %%a in ('FINDSTR /R /I /C:%%i %dir%\%%z') do (

 echo %%a >> %dest%%%i.txt"
)
)
))
)

endlocal
Pause

Can you please tell me how to add a condition on the number of characters in the domain to my script?
For example, I specify the tag "test" in the tags.txt file, and the number of characters in the bat file is "6". Only those domains are selected that contain the word test in the name and have 6 characters in the name , not counting the domain zone. Domains such as test 11.com, 2 test 2.net, test xx.org, x test x.ru, etc.
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2016-03-14
@PR0Z0N

Below is a quick procedure for counting the length of a string. In parameters, pass variable names, not values, i.e. call like this:
call:strlen str len

::original: http://forum.script-coding.com/viewtopic.php?pid=71000#p71000
:strlen  StrVar  RtnVar  --  be sure to check if the returned errorlevel is 0
setlocal
set /a "}=0"
if "%~1" neq "" if defined %~1 (
        for %%# in (4096 2048 1024 512 256 128 64 32 16) do (
            if "!%~1:~%%#,1!" neq "" set "%~1=!%~1:~%%#!" & set /a "}+=%%#"
        )
        set "%~1=!%~1!0FEDCBA9876543211" & set /a "}+=0x!%~1:~32,1!!%~1:~16,1!"
    )
)
endlocal & set /a "%~2=%}%"
exit /b

First-level domains will need to be cut off in a different way, before calling the procedure, like so:
for /f "tokens=1 delims=." %%a in ("%doaminname%") do echo.%%a

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question