VideoHelp Forum




+ Reply to Thread
Results 1 to 6 of 6
  1. Hi,

    please can help a cat ?

    I have a .txt tmp_whatsapp.py that is

    Code:
    #PY  <- Needed to identify #
    #--automatically built--
    
    adm = Avidemux()
    
    adm.clearSegments()
    
    adm.addSegment(0, 0, 346360000)
    
    adm.markerA = 0
    
    adm.markerB = 346360000
    
    adm.setHDRConfig(1, 1, 1, 1, 0)
    I need to catch the only code 346360000 (that is a variable) between the

    Code:
    adm.addSegment(0, 0, 346360000)
    or

    Code:
    adm.markerB = 346360000
    I suppose something like:

    Code:
    awk.exe "/adm.markerB/{ print $2 }" "c:\tmp_whatsapp.py"
    but this seems don't work.

    What is the correct way? thanks
    Quote Quote  
  2. You will never learn how to do this if someone has to spoon feed you.


    Goolge is your friend, try using it.


    Code:
    awk "/adm.addSegment|adm.markerB/{ sub(/\)/,\"\",$3); print $3 }" "c:\tmp_whatsapp.py"


    This works for windows. For Linux/unix make appropriate minor changes.
    Last edited by jack_666; 5th Feb 2023 at 16:30.
    Quote Quote  
  3. https://forum.videohelp.com/threads/377677-Video-batch-files#post2468981
    I posted that link many times. You can look in principle there. Once you find a line you have to parse it. Meaning finding a string withing a string. In this case I used tokens and delims:
    Code:
    @echo off
    set info="c:\tmp_whatsapp.py"
    set "cat_string="
    findstr /b /i /c:"adm.markerB"  %info% > "temp.txt"
    if %errorlevel%==0  call :get_my_cat_string "temp.txt"
    echo %cat_string%
    echo press any key to exit ... & pause>nul & exit
    
    
    :get_my_cat_string <temp file>
    set /p line= < "%~1"
    for /F "tokens=3 delims= " %%a in ("%line%") do set cat_string=%%a
    goto :eof
    which gives you:
    Code:
    346360000
    how that tokens, delims work will be clear if you for example do this:
    Code:
    for /F "tokens=1,2,3 delims= " %%a in ("%line%") do echo %%a,  %%b, %%c
    you'd get:
    Code:
    adm.markerB, =, 346360000
    in that case you'd parse all strings separated by a space, not just third token in your case
    Last edited by _Al_; 5th Feb 2023 at 17:06.
    Quote Quote  
  4. so the point is using subroutines, you can put working subroutines out of the way and just calling them. You do not clutter your main thread with noise, because after some time you do not know what is going on reading script again, so for example you can do this:
    Code:
    @echo off
    call :parsing_general adm.markerB "c:\tmp_whatsapp.py" parse_my_cat_line
    echo %parsing_result%
    echo press any key to exit ... & pause>nul & exit
    
    
    
    
    ::this you'd put on the bottom of your script, out of the way
    
    :parsing_general <searched string> <source file> <parsing method>
    set "parsing_result="
    findstr /b /i /c:"%~1"  "%~2" > "temp.txt"
    if %errorlevel%==0  call :%3 "temp.txt"
    goto :eof
    
    :parse_my_cat_line <temp file>
    set /p line= < "%~1"
    for /F "tokens=3 delims= " %%a in ("%line%") do set parsing_result=%%a
    goto :eof
    Quote Quote  
  5. for example, you downloaded awk, which you have stored somewhere, using unknown exe files, so you might as well make you own bat file called "parsing_general.bat" that will look like this:
    Code:
    REM <searched string> <source file> <parsing method>
    
    set "parsing_result="
    findstr /b /i /c:"%~1"  "%~2" > "temp.txt"
    if %errorlevel%==0  call :%3 "temp.txt"
    goto :eof
    
    :parsing_B_marker <temp file>  example: adm.markerB = 346360000
    set /p line= < "%~1"
    for /F "tokens=3 delims= " %%a in ("%line%") do set parsing_result=%%a
    goto :eof
    and using it in your scrip:
    Code:
    @echo off
    call parsing_general adm.markerB "c:\tmp_whatsapp.py" parsing_B_marker
    if not defined %parsing_result% call :fail
    if defined %parsing_result% set Bmarker=%parsing_result%
    
    echo press any key to exit ... & pause>nul & exit
    
    :fail
    rem something, set default, end script ... 
    goto :eof
    Do not hesitate creating extra BAT scripts that do something, it makes everything easier to read. You come to a script years later and still you'd be able to read it. Or someone else will read it, no problem.
    Last edited by _Al_; 5th Feb 2023 at 19:06.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!