ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
51185682482
51143082482
51185243482
52285682482
51235682482
#ifndef ver <- needs to be deleted
51185684562 <- needs to be deleted
#endif /* ver */ <- needs to be deleted
51185121482
#ifdef ver <- needs to be deleted
52286121482 <- needs to be deleted
#endif /* ver */ <- needs to be deleted
Is there a way in shell scripting to delete the lines "#ifndef ver" and "#endif /* ver */" and the number in between?
If so, what can I do?
TIA
Last edited by yawgmoth81; 02-07-2003 at 04:52 AM.
I've tested it on a bigger file and came to the conclusion that there also is an #else /* ver */
So i edited the code a bit and it works like a charm:
Code:
sed '/^#ifn\{0,1\}def ver/,/^#else/d' verschil.bak > verschil.txt
sed '/^#endif/d' verschil.txt > verschil.dat
Now it deletes from if to else and it deletes the single line endif
If someone has a better way of doing this, please tell me...
If not, then I think this topic can be closed, because everything works fine...
Thanks again everyone!
PS: I was trying something but it didn't work so well... Can I delete everything before #if(n)def and everything after #endif /* ver */ leaving everything inside these lines intact? I also need to delete the #ifndef, #else and #endif lines when I do that...
51185683111
51185683112
#ifndef ver
51185683113
#else /* ver */
52285683113
#endif /* ver */
51185683114
51185683115
Last edited by yawgmoth81; 02-10-2003 at 09:13 AM.
Originally posted by yawgmoth81 [...] Can I delete everything before #if(n)def and everything after #endif /* ver */ leaving everything inside these lines intact? I also need to delete the #ifndef, #else and #endif lines when I do that...
You mean the other way around?
Code:
sed -n '/^#ifn\{0,1\}def ver/,/^#endif/p' -e '/^#else/d' verschil.bak > verschil.txt
51185683111
51185683112
#ifndef ver
51185683113
#else /* ver */
52285683113
#endif /* ver */
51185683114
51185683115
#ifndef ver
I only want to have the numbers between #if and #else and I want to delete the rest, it works almost perfectly, there's only one small thing I can't delete the lines before the first #if.
As a small test I made this so I could see all the steps this script took:
Code:
sed '/^#endif/d' tijdens.txt > tijdens2.txt
sed '/^#else/,/^#ifn\{0,1\}def ver/d' tijdens2.txt > tijdens3.txt
sed '/^#ifn\{0,1\}def ver/d' tijdens3.txt > na5.txt
As you can see it first deletes all occurences of #endif, then it deletes everything between #else and #if, and after that it deletes the remaining #if. (usually the first one in the file)
In the example above my file will look like this:
51185683111
51185683112
51185683113
But I want it to look like this:
51185683113
Can this be done?
Last edited by yawgmoth81; 02-11-2003 at 05:58 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.