0

我的文件开头有一个自述部分,很多文件。该部分的格式如下:

###############   Read me ###############

many lines here

########################################

我想用新内容更新它们。我使用的是Windows 7,但可以访问Linux。我有EclipsePowerGREP。我不知道如何使用 OS 命令行命令执行此操作,也不知道如何使用 Eclipse 或 PowerGREP 执行此操作。有人可以帮我解决这个问题吗?

4

2 回答 2

2

如果您的部分的格式始终相同,则应该像这样简单:

###############   Read me ###############[\s\S]*?########################################

使用内联(?s)单行/点匹配所有模式,您可以使用常规.而不是,[\s\S]但这并不重要。请参阅演示

然后,根据需要替换文本块。

于 2018-06-14T04:39:54.510 回答
1

你可以很容易地做到这一点awk

输入:

###############   Read me ###############

many lines here
many lines here
many lines here

########################################
real stuff
real stuff
real stuff
real stuff
###############   Read me ###############

many lines here
many lines here
many lines here
blabla

########################################
real stuff2
real stuff2
real stuff2

命令:

awk '/######   Read me #####/{a=0}/^#+$/{a=1;next}{if(a)print}' input
real stuff
real stuff
real stuff
real stuff
real stuff2
real stuff2
real stuff2

您只需要将输出重定向到另一个文件。

说明:

  • /###### Read me #####/{a=0}当行包含###### Read me #####将变量放在0
  • /^#+$/{a=1;next}当一行只包含#将该变量放回1
  • {if(a)print}当变量在1打印行时
于 2018-06-14T05:44:17.177 回答