我正在尝试使用 删除范围sed。范围来自已知的匹配和接下来的两行。假设我想删除以 开头的所有行Don't,然后删除后面的 2 行。
请注意,我还在 sed 命令文件中进行替换。因此,我避免在我的解决方案空间中使用-nand /p。
无论出于何种原因,我想将自己限制为一次 sed 调用。
这是我的数据(data.txt):
Print Me
Please Output This line
Don't Print Me and 2 more lines
This line is no good
So is this one
We should see this line
And this one, too.
Run Code Online (Sandbox Code Playgroud)
这是我的预期输出:
Print Me
Please Output This line
We should see this line
And this one, too.
Run Code Online (Sandbox Code Playgroud)
这是一个尝试:
sed -f delete_dont_plus_2.sed data.txt
Run Code Online (Sandbox Code Playgroud)
以此为delete_dont_plus_2.sed:
/^Don't/,+2d
Run Code Online (Sandbox Code Playgroud)
这是我的结果:
sed: 1: delete_dont_plus_2.sed: …Run Code Online (Sandbox Code Playgroud)