我将如何删除最后一次出现的字符串之前的所有行。就像我有一个看起来像的文件
Icecream is good And Chocolate is good And They have lots of sugar
If I want all lines after and including the last occurrence of "And" what's the cleanest way to do this? Specifically, I want
And
They have lots of sugar
我正在做 sed -n -E -e '/And/,$p' file
但我看到这给了我第一次出现。
最佳答案
这可能对你有用(GNU sed):
sed -n '/And/h;//!H;$!d;x;//p' file
用包含 And
的行替换保留空间中的任何内容。将所有其他行附加到保留空间。在文件末尾,将模式空间交换为保持空间,并打印出与所需字符串 And
匹配的结果。
关于bash - 删除字符串最后一个大小写之前的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30958584/