Since you tagged your question also with cmd and batch-file, I want to contribute a related answer.
cmd.exe
/batch scripting does not understand HTML file format, but if your HTML file(s) look(s) like the sample data you provided (the <a>
tag and the corresponding </a>
tag are in a single line, and there is nothing else (than <br>
)), the following command line could work for you -- supposing a HTML file to process is called classes.html
and the modified data is to be written to file classes_new.html
:
> "classes_new.html" findstr /V /I /L /C:"class=\"unwanted\"" "classes.html"
This only works if the string class="unwanted"
occurs only in the <a>
tags that need to be removed.
To process multiple files, the following batch script could be used, based on the above command line:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "ARGS=%*"
setlocal EnableDelayedExpansion
for %%H in (!ARGS!) do (
endlocal
call :SUB "%%~H"
setlocal
)
endlocal
endlocal
exit /B
:SUB file
if /I not "%~x1"==".html" if /I not "%~x1"==".htm" exit /B 1
findstr /V /I /L /C:"class=\"unwanted\"" "%~f1" | (> "%~f1" find /V "")
exit /B
The actual removal of lines is done in the sub-routine :SUB
, unless then file name extension is something other than .html
or htm
. The main script loops through all the given command line arguments and calls :SUB
for every single file. Note that this script does not create new files for the modified HTML contents, it overwrites the given HTML files.