[SOLVED] how to exclude everything except a pattern with sed
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
The response to my comment about SED vs AWK is of course correct---my comparison was "apples and oranges". And AWK is definitely the right answer in many situations.
The hard thing is to always state precisely the criteria to be used when constructing code to match patterns. It sometimes takes a bit of thought to be sure you know what is to be matched and what is NOT to be matched.
Looking at the data sample in the original post, there is no obvious reason to be concerned about the column position---only the detection of the specific patterns "07" and "08". It's up to the owner of the file to be sure that an **adequate** regex is being used.
Looking at the data sample in the original post, there is no obvious reason to be concerned about the column position---only the detection of the specific patterns "07" and "08".
but then again, if you look at the sample data, a "name" and "date" column might have "08" or "07". eg a user can have account name user08, or john07 or the date column may have things like 2010/07/23. Of course, this is based on "educated" guess, since OP doesn't provide actual data format. its advisable to look at specific column and not the whole line.
correct---the safest thing is to make the code as restrictive as possible. My main point is that the user has to make the judgement as to how hard they need to work to get the results they want----you can often do very simple things IF you know what's in the file.