|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How do I search for 2 strings (AND operator) ?
I have a need to search for files containing 2 strings as in (AND operator). No one at my site seems to know if it is possible. There is only documentation for the "or' operator.
I know I can do a search, copy all the matched files into a temp directory & do the second search in the temp directory. Thanks. ![]() |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Code:
# search for 2 strings grep "string1" /path/to/files/* | grep "string2" try that. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
or Code:
find /path -name \*.lis -exec grep "string1" {} \; | grep "string2" |
|
#4
|
||||
|
||||
|
Or maybe.... Code:
awk '/string1/ && /string2/' files* |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Jim Mcnamara
I tried your command but it works like the "OR" command. I got hits with either one match. When I get a hit on a file, I need to see string1 & string2 contain in that file. Kartheg. |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Jim's command filters out lines where the string1 exists and then passes this text through another filter to find string2. The two greps are an AND. Post some sample text for review.
|
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
R u saying string1 & string2 should exist on the same line to get a hit ?. In my case string1 & string2 are on different lines. I only tried the first example.
Kartheg. Last edited by Kartheg; 11-02-2005 at 01:44 PM.. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to avoid 'unexpected operator' error when comparing 2 strings | hakermania | Shell Programming and Scripting | 9 | 08-09-2010 08:16 AM |
| Search between 2 strings | lavascript | Shell Programming and Scripting | 3 | 02-16-2010 09:02 AM |
| how to search with 2 strings. | syamkp | Shell Programming and Scripting | 2 | 03-10-2008 04:50 AM |
| Search between strings with an OR | pbsrinivas | Shell Programming and Scripting | 3 | 07-12-2007 04:46 AM |
| Search for strings | lesstjm | UNIX for Dummies Questions & Answers | 5 | 04-26-2002 09:58 AM |
|
|