Click to See Complete Forum and Search --> : Grep and regular expressions


mindcooler
08-04-2003, 07:31 PM
Ok, I need to grep a large number of text files and display all the lines containing two words (no matter where they appear on the line). I understand that this is done using a regular expression pattern given as an argument to grep, but I can't figure out the proper syntax. Could someone show me how to do this, please?

bandwidth_pig
08-04-2003, 08:07 PM
Grep is a great tool. I think what you need is:

grep 'text here' filename

serz
08-04-2003, 08:12 PM
You can also take a look to the man page. man grep. It will help if you're wanting to do something more specific.

mindcooler
08-04-2003, 08:13 PM
No, that is not it. grep "text here" filename will only return a match for the string "text here". I need to get a match no matter where the words appear on the line, and I mean each word individually. They may or may not be next to each other, I still want a match.

mindcooler
08-04-2003, 08:14 PM
I did, serz. I understand from the man page that I have to use regular expressions to do this, but powerful as they are, they're not simple to get started with. Thus, I came here.

mindcooler
08-04-2003, 08:17 PM
guess I can do:
grep word_one files | grep word_two

serz
08-04-2003, 08:25 PM
Oh wait.. playing a bit with grep...

cat filename | grep [word1,word2]

Let me know if that's what you were looking for.

mindcooler
08-04-2003, 08:31 PM
Well, mine works..didn't solve the problem I was really trying to solve, though. :(

serz
08-04-2003, 08:46 PM
Oh wait.. this is it!

cat file1 file2 | grep [word1,word2]

That works..

mindcooler
08-04-2003, 08:48 PM
Or what I wrote...:) thanks for your help...now I just have to solve the real problem, hehe