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.
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.