Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.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
Ant删除文本文件中某个关键字后的所有行_Ant - Fatal编程技术网

Ant删除文本文件中某个关键字后的所有行

Ant删除文本文件中某个关键字后的所有行,ant,Ant,是否可以使用Ant删除文本文件中特定关键字后面的所有文本行在第一次出现关键字之后。 范例 我想删除该文件中除该行之外的“Line3”关键字后面的所有内容。Ant的replaceregexp任务可以非常轻松地处理此问题: <replaceregexp file="input.txt" match="(.*Line3).*" replace="\1" flags="s" /> 简要说明:正则表达式模式捕获组中“Line3”之前的所有内容,然后继续匹

是否可以使用Ant删除文本文件中特定关键字后面的所有文本行在第一次出现关键字之后。 范例


我想删除该文件中除该行之外的“Line3”关键字后面的所有内容。

Ant的
replaceregexp
任务可以非常轻松地处理此问题:

<replaceregexp
    file="input.txt" 
    match="(.*Line3).*"
    replace="\1"
    flags="s"
/>


简要说明:正则表达式模式捕获组中“Line3”之前的所有内容,然后继续匹配其余的输入。替换只包括捕获的组,有效地删除了您不想要的部分。
s
标志打开,以便换行符与
通配符匹配。

可能可以修改文件;顺便说一下,该文件位于远程服务器或本地?请查看它的本地文本文件它可以工作,但速度非常慢。没有其他解决办法吗?
<replaceregexp
    file="input.txt" 
    match="(.*Line3).*"
    replace="\1"
    flags="s"
/>