grep multiple words any order (AND, not OR) single line, from many files
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.
kind of shows a similar thing in awk, but I'd like to use grep if possible as it seems to be way faster, and the awk example near the end only returns filenames, and I need to see the actual text. (however, even if that's easily solved, (I'm sure it must be) I'd still rather use grep).
'Tis very rare I use grep, never had the opportunity or need to use egrep. But because of your fondness for it, the next time I do need grep, egrep will pop into mind and will be investigated....
Never even finished this post and I typed "man egrep" in a terminal, quite a long man page.
In addition, three variant programs egrep, fgrep and rgrep are available. egrep is the same as grep -E. fgrep is the same as grep -F.
rgrep is the same as grep -r. Direct invocation as either egrep or fgrep is deprecated, but is provided to allow historical applications
that rely on them to run unmodified.
Actually I did come across piping early in my search, but because I'm looking for both words being in the same line, that didn't work.
grep word1 * |grep word2
It would find the files with word1, and then show the occurrences of word2 from among those files.
I like the "egrep" one because it works and is fast :-)
Maybe but I missed that you were doing a list of files - I posted before your egrep solution. If I'd thought through doing a list of files I would have told you to do the following to suppress file names.
grep -h word1 * |grep word2
By the way it doesn't just give you the file in the original - if gives you the line including the filename so when it does the second grep it IS doing it on the line the first grep returned (either with or without the -h).
There's no denying egrep (a/k/a grep -E) is a very useful tool - I use it all the time for OR searches and other purposes.
Last edited by MensaWater; 07-29-2010 at 10:39 AM.