Unconfigured Ad Widget

Collapse

Any batch file script gurus out there?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • j-rod
    Member
    • Oct 2010
    • 247

    Any batch file script gurus out there?

    I'm writing a batch file to help my wife with her work.

    She searches her work's site for content that needs to be removed. They won't help her with the tools to do it easier so she has enlisted me.

    She'll find the site that has the questionable content, view and download the source code and pick out the image numbers that are in the links. So she came to me to write a script that will search through the html source code and pull the image numbers. I have her save the source html as 'test.txt' in the folder that has the .bat file. This is what I have so far:

    Code:
    @echo off & setLocal EnableDelayedExpansion
    :start
    cls
    echo.------------------------------------
    echo     Image Number Finder Script     
    echo.------------------------------------
    echo.
    echo Have you saved the new source 'test.txt' file?
    echo.
    pause
    cls
    echo -------------------------------------------------------------------
    echo The saved source file will contain long strings of markup language.  
    echo The desired image number is contained in the image links.
    echo For instance you might want '453465759' and all of the other image numbers
    echo but the line contains:
    echo.
    echo WORKSITE.com+crappy_item,453465759
    echo.
    echo Look in the source file to get an idea of what to search for.
    echo In this case you can use 'item,4' to get a list of all image numbers 
    echo for the items in the source file.
    echo -------------------------------------------------------------------
    echo.
    set /p input=Please type the search parameter. (like 'item,4'): 
    find /i "%input%" test.txt > backend\temp.txt  
    for /f "tokens=3 delims=, " %%i in (backend\temp.txt) do (
      @echo %%i
    )>>"backend\temp2.txt"
    find /v ">" backend\temp2.txt > output.txt
    del backend\temp.txt
    del backend\temp2.txt
    cls
    echo.---------------------------------------------------------
    echo The output has been saved to 'output.txt' in this folder.
    echo.---------------------------------------------------------
    pause
    So it takes the source and FIND spits out the lines that have the image number and writes it to temp.txt. Then the FOR command spits out just the image numbers to temp2.txt but because of the HTML there are duplicate numbers.

    Code:
    441268137"
    441268137">
    So then I run it through FIND again this time printing only the lines that don't have ">" and cat out the final product to output.txt. Which is good except for the trailing "

    Code:
    ---------- BACKEND\TEMP2.TXT
    441268137"
    442100756"
    441324019"
    441324212"
    442551649"
    442099657"
    441269573"
    441269402"
    442100566"
    How do I get rid of the trailing "?

    I've tried: (test version here)

    Code:
    @echo off & setLocal EnableDelayedExpansion
    :start
    cls
    for /f "eol=-" %%i in (output.txt) do ( 
    set output=%%i
    set output=!output:~0,-1!
    echo %output%
    ) >> output2.txt
    But that won't do it. I get

    Code:
    ECHO is off.
    ECHO is off.
    ECHO is off.
    ECHO is off.
    ECHO is off.
    ECHO is off.
    Any ideas?
    NRA Life Member
  • #2
    Cali-V
    Senior Member
    • Dec 2006
    • 1942

    Have not done this in a long time, but for starters you may want to set @echo to on...
    oh this...
    It's a Single Cylinder - Single Stroke,
    Internal Combustion Engine,
    with a Free Floating Piston...

    Comment

    • #3
      j-rod
      Member
      • Oct 2010
      • 247

      Originally posted by Cali-V
      Have not done this in a long time, but for starters you may want to set @echo to on...
      Did that during debugging and to see what it gives me in relation to the final output. Then it spits out:

      Code:
      ECHO is on.
      ECHO is on.
      NRA Life Member

      Comment

      • #4
        Tripper
        Calguns Addict
        • Jan 2011
        • 7628

        you need to escape the ascii code to be able to see the double quote to be able to ignore it.
        are you actually using 'cat' as in the unix command line or a dos port of cat at least? or are you just referencing the term cat but using some other command line that does almost the same thing?

        i'm thinking of columns, but that wouldnt work if the number of characters changed.

        I usually use a small DOS program called textools, which does really good for this kind of thing, allowing for some fairly elaborate batch files.
        can you pm me the content of an example file.

        Tripper
        WTB NAA Belt Buckle
        MILITARY STRETCHER/RADIATION DETECTION KIT

        Comment

        • #5
          Tripper
          Calguns Addict
          • Jan 2011
          • 7628

          using " as the delimiter is not easy in batch, so, we're left with replacing the " with something that you can delim
          for /f "tokens=*" %%a in (test.txt) do (
          set x=%%a
          set x=!x:"= !
          for /f "tokens=1,2" %%a in ("!x!") do echo %%a
          )


          that should get you started in the right direction at least

          Tripper
          WTB NAA Belt Buckle
          MILITARY STRETCHER/RADIATION DETECTION KIT

          Comment

          • #6
            j-rod
            Member
            • Oct 2010
            • 247

            Tripper, your code worked like a charm. I owe you a beer if we cross paths in person.

            Code:
            echo -------------------------------------------------------------------
            echo.
            set /p input=Please type the search parameter. (like 'item,4'): 
            find /i "%input%" test.txt > backend\temp.txt  
            for /f "tokens=3 delims=, " %%i in (backend\temp.txt) do (
              @echo %%i
            )>>"backend\temp2.txt"
            find /v ">" backend\temp2.txt > backend\temp3.txt
            for /f "eol=- tokens=*" %%a in (backend\temp3.txt) do (
            set x=%%a
            set x=!x:"= !
            for /f "tokens=1,2" %%a in ("!x!") do echo %%a
            ) >> output.txt
            del backend\temp.txt
            del backend\temp2.txt
            del backend\temp3.txt
            cls
            echo.---------------------------------------------------------
            echo The output has been saved to 'output.txt' in this folder.
            echo.---------------------------------------------------------
            pause
            NRA Life Member

            Comment

            • #7
              Tripper
              Calguns Addict
              • Jan 2011
              • 7628

              good, glad to hear it.

              Tripper
              WTB NAA Belt Buckle
              MILITARY STRETCHER/RADIATION DETECTION KIT

              Comment

              Working...
              UA-8071174-1