If there are pairs #ifdef _WIN32/#endifthat have non-empty lines between them that you do not want to delete, use the following:
sed 'N;N;s/\n#ifdef _WIN32\n[[:space:]]*\n#endif\n/\n/;P;D'
Enter
this is the first line
#ifdef _WIN32
#endif
stuff here
more stuff here
#ifdef _WIN32
#endif
last line
Output
$ sed 'N;N;s/\n
this is the first line
// Don't delete this comment!
stuff here
more stuff here
last line
source
share