我正在嘗試從一組 html 檔案中洗掉一個標簽,但我似乎找不到正確的命令來完成這項作業。
我能夠找到標簽的行號;該標簽一共有10行需要洗掉。找到此行后,如何獲取并洗掉該行和接下來的 10 行?
這就是我所擁有的(第一個 for 回圈收集檔案,第二個 for 回圈收集所有行號。)謝謝。
::start by creating a list of html files
set i=0
for /r %%G in (*.html) do (
set /A i =1
set array[!i!]=%%G
)
set n=%i%
::second nested loop collects all lines for bottom secion to be deleted.
set j = 0
for /L %%i in (1,1,%n%) do (
for /f "delims=" %%a in ('findstr /n /c:"u-backlink u-clearfix u-grey 80" !array[%%i]!') do (
set var=%%a
set /A j =1
set array[!j!]=!var:~0,3!
)
)
set m=%j%
uj5u.com熱心網友回復:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
rem The following settings for the source directory & destination directory are names
rem that I use for testing and deliberately include names which include spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.
SET "sourcedir=u:\your files"
SET "destdir=u:\your results"
for /r "%sourcedir%" %%G in (*.html) do (
SET "linecount="
FOR /f "delims=:" %%e IN ('findstr /n /c:"u-backlink u-clearfix u-grey 80" "%%G"') DO SET /a linecount=%%e
IF DEFINED linecount (
FOR /f "usebackqdelims=" %%b IN ("%%G") DO (
SET /a linecount-=1
IF !linecount! gtr 0 ECHO %%b
IF !linecount! lss -10 ECHO %%b
)
)>"
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/485731.html
