-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete text between blank lines #1
Comments
I don't understand what you mean by For the example you have given, I'd recommend using Perl:
|
I understand the gnused This is close but it still leaves a double line, even with regex similar to yours above:
|
Your command is equivalent to Based on this unix.stackexchange thread: $ sed '/^$/{:a;N;/\n$/!ba; /kill/d}' ip.txt
This is a
sample text
demonstration.
Instead of all this, I'd just use |
Yes, that is what I was trying to work out. What does that command look like? |
# empty replacement string, since sed adds back the newline while printing
$ sed '/^$/{:a;N;/\n$/!ba; s/.*kill.*//}' ip.txt
This is a
sample text
demonstration. |
oops, clicked "close" issue by mistake. |
sed
can easily delete text between blank lines butgnused
treats blank lines differently.An example would be worthwhile. Two come to mind, replacing three blank lines with a single blank line and deleting a line and the following blank line (paragraph) if it contains a search string. Non-gnused:
sed 's/\n.*kill.*\n\n/\n/g' sample_text
sample_text
output
The text was updated successfully, but these errors were encountered: