当我有输入时:
-------------------------------------------------------------------
Sat Jul 1 09:28:03 UTC 2023 - Matej Cepl <[email protected]>
- Clean up SPEC file.
-------------------------------------------------------------------
Mon Jul 4 18:11:38 UTC 2022 - Matej Cepl <[email protected]>
- Do not unset various variables when calling make (only CFLAGS
should be set).
我只想收到以下输出:
- Clean up SPEC file.
-------------------------------------------------------------------
Mon Jul 4 18:11:38 UTC 2022 - Matej Cepl <[email protected]>
- Do not unset various variables when calling make (only CFLAGS
should be set).
答案1
只需反转您的逻辑:删除第 1 行。 1 到模式匹配(含)
sed '1,/PATTERN/d' infile
答案2
sed '0,/pattern/d' inputfile.txt
0,/pattern/
从文件开头开始匹配pattern/d
删除匹配的行以及之前的所有后续行
sed '0,/Sat/d' inputfile.txt
将输出重定向到新文件:
sed '0,/Sat/d' input.txt > outputfile.txt