0
My goal is to print the content of a file up to (and excluding) a specific pattern and I'm using the following which works as expected (even when pattern is ^$
):
sed -n '/pattern/!p;//q' file
In my quest to shorten the above command (you know, save a few bytes), I found that I could "invert" the negated print command and instead use a delete as follows:
sed '/pattern/d;//q' file
which again works as expected except when /pattern/
refers to an empty line as in /^$/
and in that case it adds the empty line itself to the output, which is weird.
The file obviously contains an empty line in my case, which is where I want to split the content.
Any idea why this happens? Is sed
buggy for this edge case? (the additional //q
does quit immediately to save on processing time when using large files)
sed --version
returns sed (GNU sed) 4.5
1
d
starts a new cycle so I'm surprised thisq
ever works for you. – Kamil Maciorowski – 2018-12-24T12:11:37.587