删除具有目标字符串的特定行出现 [英] Delete particular line occurence having target string

查看:86
本文介绍了删除具有目标字符串的特定行出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设一个包含以下内容的文件

$ cat file1

Line1

Line2

Something!

Line3



现在我想搜索关键字'Line'并仅删除第二个匹配的行,即'Line2'



我知道删除所有匹配的行如下。



$ sed -i'/ Line / d'file1



请帮帮我!!

Assume a file with below contents
$cat file1
Line1
Line2
Something!
Line3

Now I wanted to search keyword 'Line' and delete only the second matching line i.e., 'Line2'

I am aware to delete all the matching lines as below.

$sed -i '/Line/d' file1

Please help me!!

推荐答案

cat file1

Line1

Line2

东西!

Line3



现在我想搜索关键字'Line '并且只删除第二个匹配的行,即'Line2'



我知道删除所有匹配的行如下。


cat file1
Line1
Line2
Something!
Line3

Now I wanted to search keyword 'Line' and delete only the second matching line i.e., 'Line2'

I am aware to delete all the matching lines as below.


sed -i'/ Line / d'file1



请帮助我!!
sed -i '/Line/d' file1

Please help me!!


这篇关于删除具有目标字符串的特定行出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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