943,537 Members | Top Members by Rank

Ad:
Nov 26th, 2008
0

how to delete the special lines in all cpp files?

Expand Post »
Some of my source files include the following code.
Shell Scripting Syntax (Toggle Plain Text)
  1. #ifndef AAAAAAAAAAAA
  2. #define AAAAAAAAAAAA
  3. #if !defined(__lint) && !defined(_lint)
  4. XXXXXXXXXXXXXXXXXXXXXXXXX;
  5. #endif
  6. #endif

I want to delete line1, 2, 6. So, Could somebody tell me how to do it? thank you in advance!
Reputation Points: 14
Solved Threads: 6
Light Poster
littlestone is offline Offline
42 posts
since Mar 2008
Nov 27th, 2008
0

Re: how to delete the special lines in all cpp files?

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:

Quote ...
$ 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
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007
Nov 27th, 2008
0

Re: how to delete the special lines in all cpp files?

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"
Reputation Points: 14
Solved Threads: 6
Light Poster
littlestone is offline Offline
42 posts
since Mar 2008
Nov 28th, 2008
0

Re: how to delete the special lines in all cpp files?

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
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007
Nov 28th, 2008
0

Re: how to delete the special lines in all cpp files?

Thank you so much.
Reputation Points: 14
Solved Threads: 6
Light Poster
littlestone is offline Offline
42 posts
since Mar 2008
Nov 28th, 2008
0

Re: how to delete the special lines in all cpp files?

Glad to help out

Best wishes,

Mike
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Shell script help
Next Thread in Shell Scripting Forum Timeline: umask





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC