我需要删除一个匹配的行和一个之前的行.
例如,在下面的文件中,我需要删除第1行和第1行. 2.
例如,在下面的文件中,我需要删除第1行和第1行. 2.
我试过“grep -v -B 1”page.of.“1.txt
我希望它不会打印匹配的行和上下文.
我尝试了How do I delete a matching line,the line above and the one below it,using sed?,但无法理解sed的用法.
---1.txt-- **document 1** -> 1 **page 1 of 2** -> 2 testoing testing super crap blah **document 1** **page 2 of 2**
你想做一些与
answer given非常相似的事情
原文链接:https://www.f2er.com/bash/386932.htmlsed -n ' /page . of ./ { #when pattern matches n #read the next line into the pattern space x #exchange the pattern and hold space d #skip the current contents of the pattern space (prevIoUs line) } x #for each line,exchange the pattern and hold space 1d #skip the first line p #and print the contents of pattern space (prevIoUs line) ${ #on the last line x #exchange pattern and hold,pattern now contains last line read p #and print that }'
并作为一条线
sed -n '/page . of ./{n;x;d;};x;1d;p;${x;p;}' 1.txt