批次从第n行中删除文件数量的x行数
我正在尝试从一组HTML文件中删除标签,但似乎找不到正确的命令来完成这项工作。
我能够找到标签的行号;该标签总共需要删除10行。一旦找到了这条线,我将如何获得并删除所说的行&接下来的10行?
这是我拥有的(循环收集文件的第一个,第二个收集所有行号的循环。)谢谢。
::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%
I am trying to remove a tag from a set of html files and I can't seem to find the right commands to do the job.
I am able to find the line number of the tag; the tag is a total of 10 lines that need to be deleted. Once I find this line, how do I got and delete said line & next 10 lines?
Here's what I have (a first for loop to collect files, a second for loop that collects all line numbers.) thank you.
::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%
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从
sourcedir
启动目标文件的递归目录列表。初始化
linecount
to nothing 并使用findstr
来定位目标字符串。%% e
将设置为找到的行数,set
将其设置为linecount
。如果找到字符串,
linecount
现在将包含一个值,因此请阅读每行并计算。如果linecount
在0和-10之间,则我们不echo
输出文件的行。我最初将所有生成的文件都放在一个目录中。您要随意更改。
修订以生成一个临时文件(,其中将是无关紧要的),然后将该文件移到原始文件上。
在应用真实数据之前,请务必针对测试目录进行验证。
Start a recursive directory list of the target files from
sourcedir
.Initialise
linecount
to nothing and usefindstr
to locate the target string.%%e
will be set to the number of the line found,set
this intolinecount
.If the string was found,
linecount
will now contain a value, so read each line and count down. Iflinecount
is between 0 and -10, we don'techo
the line to the output file.I originally put all the generated files in the one directory. Yours to change at will.
Revised to generate a temporary file (quite where would be irrelevant) and then move that file over the original.
Always verify against a test directory before applying to real data.