使用sed(或awk)删除图案上方的行范围
我有以下代码,该代码将删除带有模式的banana行及其后的两行: sed '/banana/I,+2 d' file 到目前为止,一切都很好!但我需要它来除去2行之前 banana,但我不能用“减号”或任何(类似于得到它grep -v -B2 banana file应该做的,但没有): teresaejunior@localhost ~ > LC_ALL=C sed '-2,/banana/I d' file sed: invalid option -- '2' teresaejunior@localhost ~ > LC_ALL=C sed '/banana/I,-2 d' file sed: -e expression #1, char 16: unexpected `,' teresaejunior@localhost ~ > LC_ALL=C sed '/banana/I,2- d' file sed: -e …