我对 Linux 有点陌生,但遇到了问题。我有一个名为file_a.txtMy first command的文本文件
grep -A 12 ".production =" file_a.txt
输出是几个块。每块字符串包含 13 行
我特别想grep
从原始文件中删除我使用命令获得的所有字符串块,我file_a.txt不想将 grep 输出发送到新文件。我也不想使用,grep -v因为它在我的情况下不起作用。
我尝试过类似这样的事情,但没有任何效果:
cut < grep -A 12 ".production =" file_a.txt
sed -i '/grep -A 12 ".production ="/d' file_a.txt
我想你正在寻找这个:
sed -i '/.production =/,+12d' file_a.txt
Run Code Online (Sandbox Code Playgroud)
当 sed 发现您的模式时,它会“删除”12 行
(警告,就地修改 file_a.txt )