how to delete the special lines in all cpp files?

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2008
Posts: 42
Reputation: littlestone is an unknown quantity at this point 
Solved Threads: 6
littlestone littlestone is offline Offline
Light Poster

how to delete the special lines in all cpp files?

 
0
  #1
Nov 26th, 2008
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!
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

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

 
0
  #2
Nov 27th, 2008
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
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 42
Reputation: littlestone is an unknown quantity at this point 
Solved Threads: 6
littlestone littlestone is offline Offline
Light Poster

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

 
0
  #3
Nov 27th, 2008
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"
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

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

 
0
  #4
Nov 28th, 2008
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
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 42
Reputation: littlestone is an unknown quantity at this point 
Solved Threads: 6
littlestone littlestone is offline Offline
Light Poster

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

 
0
  #5
Nov 28th, 2008
Thank you so much.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

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

 
0
  #6
Nov 28th, 2008
Glad to help out

Best wishes,

Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC