在一行上找到匹配项,删除该行以及之前的行

时间:2016-02-18 15:59:18

标签: bash unix

我的文件文件如下,

ukncsavix302:  
Red Hat Enterprise Linux Server release 6.6 (Santiago)  
ukncsavix353:  
Red Hat Enterprise Linux Server release 6.5 (Santiago)  
uknwsavix354:  
Red Hat Enterprise Linux Server release 6.5 (Santiago)  

现在我需要在其上找到带有“6.5”的行,删除该行并删除其上方的一行。

有人可以帮我打破这个吗?

1 个答案:

答案 0 :(得分:2)

试试这个:

tac file.txt | sed -e '/6.5/,+1d' | tac

如果需要,输出到新文件:

tac file.txt | sed -e '/6.5/,+1d' | tac > newfile.txt
相关问题