Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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
Regex 正则表达式-grep、sed、awk-处理大型文本文件_Regex_Awk_Sed_Grep_Find - Fatal编程技术网

Regex 正则表达式-grep、sed、awk-处理大型文本文件

Regex 正则表达式-grep、sed、awk-处理大型文本文件,regex,awk,sed,grep,find,Regex,Awk,Sed,Grep,Find,我一直在使用文本编辑器来完成正则表达式的工作。它工作得很好,但现在我很抱歉,示例文件的大小是10GB,因此它会阻塞文本编辑器 您建议使用什么?您是否有一些样本或网站可供参考? 我在看这是我发现人们用它做很多事情 查找-是一个文件搜索 grep-是一种基于行的搜索 awk-是一种查找和替换搜索 sed是一种编程语言搜索 我要找的是: 你可以放正则表达式:(.*),[a-z]然后 文本文件: some-text-file : threw this cat and then sat on the

我一直在使用文本编辑器来完成正则表达式的工作。它工作得很好,但现在我很抱歉,示例文件的大小是10GB,因此它会阻塞文本编辑器

您建议使用什么?您是否有一些样本或网站可供参考?

我在看这是我发现人们用它做很多事情

  • 查找-是一个文件搜索
  • grep-是一种基于行的搜索
  • awk-是一种查找和替换搜索
  • sed是一种编程语言搜索
我要找的是:

你可以放正则表达式:(.*),[a-z]然后

文本文件:

some-text-file : threw this cat and then sat on the mat  
some-other-text-file : the quick brown flew free then the fox fell
yet-another-text-file : i hope this explains this and that thoroughly  
渴望

  • 找出以“some”开头的那一行,找到“then”,然后把从头到尾的所有内容都记下来
  • 输出主题:如果找到一些,则放入“一些:
  • 如果找到“then”,则在同一行中输出显示从该点到句子结尾的所有文本
正则表达式(哪一个可以只输出值而不使用此语法修改它

此外,我想匹配多行和返回匹配文本只

find: (^some)(.*)(then)(.*) return: Subject: some then: \4
这将有效地处理任何大小的输入文件:

$ sed 's/^some.*then\(.*\)/Subject: some then:\1/' file
Subject: some then: sat on the mat
Subject: some then: the fox fell
yet-another-text-file : i hope this explains this and that thoroughly

如果这还不是你所需要的,那么编辑你的问题以澄清你的要求,并包括上面不适用的示例输入/输出。

第三行如何匹配任何东西?那么你尝试过什么,你的问题是什么?在示例输入/输出中包括一行,如
他们运行,然后他们行走,然后他们坐在那里,这样我们可以查看是否希望输出从行中的第一个或最后一个
开始,然后
。并修正您的要求,说您想要
主题:一些然后:
主题:一些结果:然后
,但不能两者兼而有之。
$ sed 's/^some.*then\(.*\)/Subject: some then:\1/' file
Subject: some then: sat on the mat
Subject: some then: the fox fell
yet-another-text-file : i hope this explains this and that thoroughly