Search code examples
batch-filesetexpressionfindstr

Batch commands for rds


I have a project for my Radio Station where I copy the text within a .wsx file of what is on air and parse it to a Audio Processor in my private network for RDS Display using a wget command like

set /p TEXTO= 0<R:\40.wsx
wget -q "http://x.x.x.x:7380/parameter/fm/rds/rds_rt=%TEXTO%" -O NUL

It works great but it won't filter if it's music or promotions.

My challenge is to be able to filter and only parse music names.

For the process I marked the Files that i don't want to show up like commercial, or promotions to start with a "@-" without the quotes.

So the text will show like @-Promo1

My Code:

for /F "delims=" %%a in ('FINDSTR "\<@-.*"  C:\RDS\PRUEBAS\txt1.wsx') do set 
"VAR=%%a"
  echo %VAR% 
 if "%VAR%" == "true" (
    set /p VAR=0<C:\FILEPATH\LOS40.wsx & wget -q 
"http://x.x.x.x:7380/parameter/fm/rds/rds_rt=%VAR%" -O NUL 
) else (
    set /p TEXTO=0<C:\FILEPATH\ENVIVO.wsx & wget -q 
"http://x.x.x.x:7380/parameter/fm/rds/rds_rt=%TEXTO%" -O NUL
)

I can't seem to find a correct way to filter it.

pls Heelpp..


Solution

  • for /F "delims=" %%a in ('FINDSTR "\<@-.*"  C:\RDS\PRUEBAS\txt1.wsx') do set 
    

    should be

    for /F "delims=" %%a in ('FINDSTR /b "@-"  C:\RDS\PRUEBAS\txt1.wsx') do set 
    

    to find those lines in the .wsx file that do /b begin with "@-"

    If you want to find those lines that do not begin with "@-" then add /v to the /b.

    The result will be a line from the file which does [not] begin with "@-" which will be placed in %%a.

    If you simply assign %%a to a variable as you are doing, that variable will contain after the for the last value that was assigned to it.

    If you want to execute your wget on each name, then use

    for /F "delims=" %%a in ('FINDSTR /B "@-"  C:\RDS\PRUEBAS\txt1.wsx') do (
     echo %%a
    )
    

    and between the parentheses you can execute commands using %%a as a filename.

    Quite what you propose to do is obscure. I've no idea what the set/p from an unexplained file is meant to do, but be aware that any code between parentheses is subject to the delayedexpansion trap - please explain what processing you intend to apply to the filenames that do[not] match a leading @-.

    You should read SO items on delayed expansion (it's documented with and without the space) to understand the problems with and solutions to processing values that are altered within a loop.