Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
I need to clarify my question a bit. I need an AND function that will find 'x AND y' OR 'y AND x'. Your solution works as long as x precedes y, but I also want to find y followed by x using the shortest command possible. Is there not just an AND symbol or something like egrep 'x&y' which finds x.*y or y.*x? I figured that since they threw in an symbol for the OR logical function, I assumed there would be a symbol for AND, or similar simple way of performing the AND logical function.
eddiebaby1023, I do like to keep things as short as possible, but I am fairly new to this as well. The way I was shown was to use cat when piping multiple greps, thank you for pointing out it is not necessary. That will definitely help me shorten things up.
Also, thanks for the examples. They work well with 2 variables. However, what would you do if the number of variables were increased?
For example, lets say you have a text log from thousands of hosts. You want to find a log entry that contains 15 hostnames, and the names could be in any order.
Is the only way to find that entry to pipe 15 greps together?
rather than write hostname1-15, you get the idea
the second example would present only lines that contained all 15 hostnames (strings), not sure what logs you would be looking at that would have 15 hostnames on a single line but there it is
this will give you the logical ANDing that you were seeking
Sigh. I didn't notice until after this post that this was such an old resurrected thread.
Originally Posted by boozer_2
But I want them both. ...
You may be interested in:
glark - Search text files for complex regular expressions
glark [options] expression file ...
Similar to "grep", "glark" offers: Perl-compatible regular expressions,
color highlighting of matches, context around matches, complex expres-
sions ("and" and "or"), grep output emulation, and automatic exclusion
of non-text files. Its regular expressions should be familiar to per-
sons experienced in Perl, Python, or Ruby. File may also be a list of
files in the form of a path.