Issue
I have a text file like
some
important
content
goes here
---from here--
some
unwanted content
I am trying to delete all lines after ---from here--
including ---from here--
. That is, the desired output is
some
important
content
goes here
I tried sed '1,/---from here--/!d' input.txt
but it's not removing the ---from here--
part. If I use sed '/---from here--.*/d' input.txt
, it's only removing ---from here--
text.
How can I remove lines after a pattern including that pattern?
EDIT
I can achieve it by doing the first operation and pipe its output to second, like sed '1,/---from here--/!d' input.txt | sed '/---from here--.*/d' > outputput.txt
.
Is there a single step solution?
Solution
Another approach with sed:
sed '/---from here--/,$d' file
The d
(delete) command is applied to all lines from first line containing ---from here--
up to the end of file($
)
Answered By - SLePort