I'm trying to remove all lines after the first blank line in a file with a git filter using sed.
This seems to remove everything after the blank line
sed -i '/^$/q' test.rpt
How do I also include the blank line itself to be deleted?
If this is GNU sed, just use Q
instead of q
.
sed -i '/^$/Q' test.rpt
For BSD sed, use -n
switch to suppress automatic printing, and print lines manually. E.g:
sed -n -i '/^$/q;p' test.rpt
PS: You might want to change the regex to ^[[:blank:]]*$
to regard lines of all blank characters as blank lines as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With