如何删除特定的事件匹配模式 [英] How to delete the matching pattern from given occurrence

查看:95
本文介绍了如何删除特定的事件匹配模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图删除匹配的模式,从第二个开始发生,使用 SED AWK 。该输入文件包含以下信息:

  ABC
DEF
ABC
GHI
JKL
ABC
XYZ
ABC

我要的删除二审模式 ABC 。输出应如下:

  ABC
DEF
GHI
JKL
XYZ


解决方案

整洁 SED 解决方案:

  SED'/ ABC / {2,$ D}'的test.txt
ABC
DEF
GHI
JKL
XYZ

I'm trying to delete matching patterns, starting from the second occurrence, using sed or awk. The input file contains the information below:

abc
def
abc
ghi
jkl
abc
xyz
abc

I want to the delete the pattern abc from the second instance. The output should be as below:

abc
def
ghi
jkl
xyz

解决方案

Neat sed solution:

sed '/abc/{2,$d}' test.txt
abc
def
ghi
jkl
xyz

这篇关于如何删除特定的事件匹配模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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