Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.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
Bash Linux sed删除带模式的2行_Bash_Sed - Fatal编程技术网

Bash Linux sed删除带模式的2行

Bash Linux sed删除带模式的2行,bash,sed,Bash,Sed,我知道如何删除所有与具有 sed -i '/pattern/d' file 但是我应该如何删除这一行和下一行呢 例如,在下面的文件中,我想删除所有的“Apple”和next水果 Apple Peach Lemon Apple Banana Peach 预期产出: Lemon Peach 有人知道怎么做吗?使用N将下一行读入模式空间 sed '/Apple/{$!N;d}' file 使用N将下一行读入模式空间 sed '/Apple/{$!N;d}' file 请尝试以下内容(用GNU

我知道如何删除所有与具有

sed -i '/pattern/d' file
但是我应该如何删除这一行和下一行呢

例如,在下面的文件中,我想删除所有的“Apple”和next水果

Apple
Peach
Lemon
Apple
Banana
Peach
预期产出:

Lemon
Peach

有人知道怎么做吗?

使用
N
将下一行读入模式空间

sed '/Apple/{$!N;d}' file

使用
N
将下一行读入模式空间

sed '/Apple/{$!N;d}' file

请尝试以下内容(用GNU
sed编写和测试)


请尝试以下内容(用GNU
sed编写和测试)


我愿意接受这个而不是我的。我知道
+1
是一个GNU扩展,但我还是会接受它而不是我的。我知道
+1
是GNU扩展,但仍然