Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 如果段落包含某些单词,则批处理文件以删除段落_Batch File - Fatal编程技术网

Batch file 如果段落包含某些单词,则批处理文件以删除段落

Batch file 如果段落包含某些单词,则批处理文件以删除段落,batch-file,Batch File,我需要从.txt文件中删除一个段落,但前提是它包含字符串“Type:sequence”。每个段落之间有两行新行,一行“^**”,还有两行新行。我发现了很多关于如何删除包含某个单词的行的信息,但没有关于段落的信息 如果你不怕正则表达式,你可以用它来解决这个问题 你的规格有点不清楚。根据我对您的布局的理解,我认为以下示例文本中只应保留第2、6和8段: test.txt This is paragraph 1 that should be deleted xxxx Type: Certain xxxx

我需要从.txt文件中删除一个段落,但前提是它包含字符串“Type:sequence”。每个段落之间有两行新行,一行“^**”,还有两行新行。我发现了很多关于如何删除包含某个单词的行的信息,但没有关于段落的信息

如果你不怕正则表达式,你可以用它来解决这个问题

你的规格有点不清楚。根据我对您的布局的理解,我认为以下示例文本中只应保留第2、6和8段:

test.txt

This is paragraph 1 that should be deleted
xxxx Type: Certain xxxx
End of paragraph 1

^**

This is paragraph 2 that should be preserved
End of paragraph 2

^**

This is paragraph 3 Type:
Certain That should be deleted
End of paragraph 3

^**

This is paragraph 4
Type: Certain That should be deleted
End of paragraph 4

^**

Type: Certain

^**

This is paragrpah 6 that should be preserved
End of paragraph 6

^**

This is paragraph 7 that should be deleted
Type: Certain. End of paragraph 7

^**

This is paragraph 8 that should be preserved

^**

This is paragraph 9 that should be deleted
Type: Certain
这里有一个使用JREPL.BAT的解决方案

通过分别更改
p
d
的定义,可以修改段落分隔符和删除触发器的正则表达式搜索

@echo off
setlocal
set "p=\r?\n\r?\n\^\*\*\r?\n\r?\n"  %= Paragraph delimiter =%
set "d=\bType:\s+Certain\b"         %= Text that indicates deletion =%

set "find=(%p%)?(?:[\s\S](?!%p%))*%d%[\s\S]*?(?:(%p%)|(?![\s\S]))"
set "repl=$txt=($1&&$2)?$1:''"

call jrepl find repl /m /v /jq /f test.txt /o -
这是删除段落后的文件:

This is paragraph 2 that should be preserved
End of paragraph 2

^**

This is paragrpah 6 that should be preserved
End of paragraph 6

^**

This is paragraph 8 that should be preserved

类型的可能性:第一段或最后一段中的某些
使问题有点复杂。

欢迎使用!请编辑您的问题,并提供一些代码样本。您的问题离题(因为您只是请求代码)且不清楚(您如何定义“段落?”。请阅读并学习!