How do I grep out lines above till certain pattern is found
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.
You can't buffer backwards - you have to buffer reads until they match your criteria. Grep won't do it - maybe awk/perl/ ...
And what on earth does "filter out" mean ? - include or exclude ?.
@blason: Please place your code snippets inside [CODE]...[/CODE] tags for better readability. You may type those yourself or click the "#" button in the edit controls.
As others have indicated, a little more clarity about what you are trying to do would be helpful.
In particular, does "filter out" mean delete or extract?
Do you want the # line to be deleted/extracted as well, and which one exactly?
Please review the Site FAQ for guidance in posting your questions and general forum usage. Especially, read the link in that page, How To Ask Questions The Smart Way. The more effort you put into understanding your problem and framing your questions, the better others can help!
Thanks for the input and let me correct or rephrase. filter out as in I need include those lines only and then count backwards till the end of the file where file starts with "#"
Well, eventually I need to find out the recent lines since recent additions get added above it. Hence I was not sure how to include only recent changes or lines which were added yesterday.
After testing, I have corrected my post#9.
I think the O/P wants to print from the last # line before the matched line, up to the matched line.
In contrast, /^#/,/00:22:44/ is from the first # line until the matched line.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.