I'm trying to use sed to delete all occurrences of
#ifdef _WIN32
#endif
Where all that exists between #ifdef and #endif is an empty line. I have limited experience using sed, I've read some documentation on the multi line features but I can't seem to figure it out. Any help is appreciated!
To delete a line, we'll use the sed “d” command. Note that you have to declare which line to delete. Otherwise, sed will delete all the lines.
By using N and D commands, sed can apply regular expressions on multiple lines (that is, multiple lines are stored in the pattern space, and the regular expression works on it): $ cat two-cities-dup2.
Use multiple patterns at once with SedLook out for the semicolon(;) to add more patterns within the single command.
The sed command can remove the lines of any range. For this, we just have to enter 'minimum' and 'maximum' line numbers. In this example, we will remove the lines ranging from 4 to 7 numbers. After removing these ranges of lines, our file will look like this.
You can try sed -e '/^#ifdef _WIN32/,/^#endif/d'
but it does not generalize to more complex cases of nesting.
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