使用grep在大块文本中匹配和擦除模式 [英] Use grep to match and erase a pattern in a large chunck of text

查看:163
本文介绍了使用grep在大块文本中匹配和擦除模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 但是/ CC as / IN 1 / Z教会/ NP历史学家/ NN / Fc 
as / IN 1 / Z/ Fe破裂/ NN和/ CC新/ JJ开始/ NN世纪/ NN ./Fp
====== >找到的匹配:\#\#[az] + \ / NN \#\#
======>找到匹配:be \ / V [AZ] +( \s [。] {0,10})?\#\#
======>找到匹配:\#\#\sof\ / IN

我想使用(linux)终端命令 grep 来匹配和清除所有以

======>匹配为开头的行:



以及以换行符。



因此,根据前面的示例,我想运行grep并获取以下输出:


但是/ CC as / IN 1 / Z church / NP historian / NN / Fc
as / IN 1 / Z/ Fe破裂/ NN和/ CC新/ JJ开始/ NN世纪/ NN。/ FP


预先感谢您的帮助

解决方案

  grep -E -v'^ ======> match found:。+ $'file.txt 

-E 打开扩展正则表达式, -v 取消输出,即打印所有行不匹配。


I have a very large text file which contains data similar to the following:

     but/CC as/IN 1/Z church/NP historian/NN/Fc 
     as/IN 1/Z "/Fe rupture/NN and/CC new/JJ beginning/NN century/NN ./Fp
    ======>match found: \#\#[a-z]+\/NN\#\#
    ======>match found: be\/V[A-Z]+(\s[.]{0,10})?\#\#
    ======>match found: \#\#\sof\/IN

I would like to use the (linux) terminal command grep to match and erase all the lines that start with:

======>match found:

and end with a newline character.

Thus, according to the previous example, I'd like to run grep and obtain the following output

but/CC as/IN 1/Z church/NP historian/NN/Fc as/IN 1/Z "/Fe rupture/NN and/CC new/JJ beginning/NN century/NN ./Fp

Thank you in advance for your help

解决方案

grep -E -v '^======>match found:.+$' file.txt

-E turns on extended regular expressions, and -v negates the output, i.e. prints all lines that don't match.

这篇关于使用grep在大块文本中匹配和擦除模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆