awk或者sed:以下模式删除n行 [英] sed or awk: delete n lines following a pattern

查看:122
本文介绍了awk或者sed:以下模式删除n行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何在sed(或任何类似的工具 - awk的为例)混合模式和数字范围?我想要做的就是在一个文件中匹配某些行,并在继续之前删除下n行,我想这样做,作为管道的一部分。

How would I mix patterns and numeric ranges in sed (or any similar tool - awk for example)? What I want to do is match certain lines in a file, and delete the next n lines before proceeding, and I want to do that as part of a pipeline.

推荐答案

我将在此一展身手。

要的模式后,删除5条线路(包括与模式的行):

To delete 5 lines after a pattern (including the line with the pattern):

sed -e '/pattern/,+5d' file.txt

要删除的模式后,5线(不包括与模式的行):

To delete 5 lines after a pattern (excluding the line with the pattern):

sed -e '/pattern/{n;N;N;N;N;d}' file.txt

这篇关于awk或者sed:以下模式删除n行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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