![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Grepping for two strings that MUST exist on the same line | Rally_Point | Shell Programming and Scripting | 6 | 06-02-2009 12:12 AM |
| Grepping for Exact Strings | SkySmart | Shell Programming and Scripting | 27 | 05-04-2009 02:12 PM |
| how to extract multiple strings from a line | vin_eme | Shell Programming and Scripting | 3 | 01-22-2009 01:46 PM |
| Trouble grepping for multiple strings | thecoffeeguy | Shell Programming and Scripting | 5 | 05-16-2008 06:53 AM |
| Grepping for strings | t4st33@mac.com | UNIX for Dummies Questions & Answers | 5 | 06-21-2007 12:51 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Grepping Multiple Strings on the Same Line 'Or'
I've got this command that I've been using to find strings on the same line, say I'm doing a search for name:
find . -name "*" | xargs grep -i "Doe" | grep -i "John" > output.txt This gives me every line in a file that has John and Doe in it. I'm looking to add a OR operator for the second grep statement, so that I can grep for "John" OR "Jonathon" for example. In this example, I know that I could just enter "Jo*" but I don't want any other terms like Jose or Jonas. I tried find . -name "*" | xargs grep -i 'Doe\|John' > output.txt but that didn't seem to work. Thanks in advance. |
|
||||
|
Quote:
find . -name "*"| xargs grep -i Doe| grep -i -e John -e Jonathon >output.txt find . -name "*"| xargs grep -i Doe| egrep -i "(John|Jonathon)" >output.txt You can also combine the find and xargs commands: find . -name "*" -exec grep -i Doe {} \; | grep -i -e John -e Jonathon >output.txt |
|
||||
|
Another approach. But don't have the script or the output file in the same tree as the find ! Code:
#!/bin/ksh
(
find . -type f -print | while read FILENAME
do
echo "${FILENAME}"
egrep -iw "Doe" "${FILENAME}"|egrep -iw "John|Jonathan"
done
) > /tmp/output
Last edited by methyl; 06-12-2009 at 02:05 PM.. Reason: Stopped script finding output file! |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|