Some of my source files include the following code.

#ifndef AAAAAAAAAAAA
#define AAAAAAAAAAAA
  #if !defined(__lint) && !defined(_lint)
    XXXXXXXXXXXXXXXXXXXXXXXXX;
  #endif
#endif

I want to delete line1, 2, 6. So, Could somebody tell me how to do it? thank you in advance!

Recommended Answers

All 5 Replies

Hey There,

If you just want to delete files that (I'm assuming) begin with a pound character and start with ifndef,define or endif, you could do it (not very generically in this example) by using sed:

$ sed '/^#[ifndef|define|endif]/d' FILENAME
#if !defined(__lint) && !defined(_lint)
XXXXXXXXXXXXXXXXXXXXXXXXX;
#endif

You can also be more generic so that you delete more or less lines with less code by using regular expressions. This should take care of your immediate problem, though.

Happy THanksgiving :)

, Mike

Hi eggi,

Thank you for your reply. I don't want to remove all the line that begin with a pound character and then start with ifndef,define or endif. I just want to remove the three lines in the 6 lines.

In addition, I don't know why your the sed command remove all the lines begin with a pound character. such as "#include aaaa.h"

Hey again,

In that case it might just be simpler to do:

sed -e 1,2d -e 6d FILENAME

The reason the command above removes any line starting with a pound is that I write answers in too many different languages ;) The proper syntax for this command (although, actually, it was syntactically correct (no errors) but didn't do what was expected) would be to do:

sed '/^#\(ifndef\|define\|endif\)/d' FILENAME

Best wishes,

Mike

Thank you so much.

Glad to help out :)

Best wishes,

Mike

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.