computing
  • 2

Solved Batch File – Read Html Tags And Output To File

  • 2

Hello – I need to read the text between <title> and </title> tags in multiple .html files in a file directory and output this text to a new text file. The number and names of the .html files will vary, so I need to be prepared for that. I am hoping this can be done with a plain batch file that can run under Windows XP.

Any help on this problem is much appreciated.

Share

1 Answer

  1. this might work, but only if

    <title>

    and

    </title>

    are both on the same physical line.
    ::===begin script
    @echo off & setlocal enabledelayedexpansion
    for /f “tokens=*” %%a in (‘findstr /i /c:”<title>” *.htm’) do (
    set x=”%%a”
    :: you might get away with using a single delim char, but i tried to “safety” with 3.
    set x=!x:title^>=*@$!
    for /f “tokens=2 delims=*@$” %%b in (!x!) do (
    set y=”%%b”
    set y=!y:~1,-3!
    echo FINAL OUTPUT is: !y!
    >>titles echo !y!
    )
    )
    ::=== end
    ps: most of us have dealt with hospital procedures, and these are mild compared to some. Ce la vie!

    • 0