Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
No. I don't think so. sed is a line editor, it reads on a line-per-line basis.
You're better of with either awk or a Perl script, in my humble opinion.
In Perl, your algo could be something like:
-open file for reading
-open up 2 files for writing: 1 to save the blocks you want to keep, 1 for the others
-allocate an array that you're going to use as a buffer
-loop over all lines in the file you're reading
-if line =~ <stuff>, you're at the beginning of a new block.
In such case, you need to check if you want to keep the block you've just read and
print it to the right output file.
-else, you need to simply append the line you've read to your buffer.
-after the loop, close all files
Once the script has done it's work, check out it's two output files. If the file that contains
the blocks you want to keep seems OK to you, mv it over the original file.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.