| | |
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:
Solved Threads: 6
Some of my source files include the following code.
I want to delete line1, 2, 6. So, Could somebody tell me how to do it? thank you in advance!
Shell Scripting Syntax (Toggle Plain Text)
#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!
•
•
Join Date: Oct 2007
Posts: 399
Reputation:
Solved Threads: 47
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:
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
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
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!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
•
•
Join Date: Mar 2008
Posts: 42
Reputation:
Solved Threads: 6
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"
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"
•
•
Join Date: Oct 2007
Posts: 399
Reputation:
Solved Threads: 47
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
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!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
•
•
Join Date: Oct 2007
Posts: 399
Reputation:
Solved Threads: 47
Glad to help out 
Best wishes,
Mike

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!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
![]() |
Other Threads in the Shell Scripting Forum
- Previous Thread: uniq and sort
- Next Thread: umask
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting





