Reputation: 51
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?
Upvotes: 4
Views: 411
Reputation: 50750
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.
Upvotes: 4