- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- grep files
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2004 02:24 PM
08-09-2004 02:24 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2004 02:28 PM
08-09-2004 02:28 PM
Solution# egrep "abc|def" ./*
or
# grep -E "abc|def" ./*
Regards,
Dave
I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2004 04:13 PM
08-09-2004 04:13 PM
Re: grep files
If you want to get the files contents which contain anyof the pattern "abc" or "def" then use
grep -E "abc | def" ./*
egrep -i "abc | def" ./*
-i used to ignore the case type
And more we can do it with multiple -e option as,
grep -ie abc -ie def filename
It will do grep abe / def.
If you want to print only the lines with abc and def then,
grep -E 'abc' filename | grep -E 'def'
It will do that.
If you want to use patterns with - then use -e option
Regards
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2004 05:19 PM
08-09-2004 05:19 PM
Re: grep files
grep -l abc * | xargs grep -l def
Like Muthu writes, the established way of finding a file with both abc AND def ON ONE LINE is to chain greps:
grep abc * | grep def
or, if you know def follows abc:
grep -E "abc.*def" *
or, I suppose you could use a convoluted:
grep -E "abc.*def|def.*abc" *
However, I think the author wants to list filenames for those fiels that contain both 'abc' and 'def', but not necesarilly on one line.
So use: grep -l abc x* | xargs grep -l def
The first grep creates a list of filenames that contain abc, then xargs combines that list into agruments fro a second grep which again reads the whole file, not just the lines with 'abc'.
Bonus answer... in AWK:
awk '//{if (FNR==1){a=d=x=0}} /abc/{a++} /def/{d++} {if (a&&d&&!x++) {print FILENAME}}' *
And in PERL
perl -e 'while ($f=shift @ARGV){$a=$d=0;open (F,"<$f");while (
Both clear flags for each condition when a new file is started (in AWK we use FNR=1).
AWK limits printing FILENAME to once through a flag. PERL only tests at the end of the current file. Perl is easier to read (imho), but a 'lot' longer to write.
Grins,
Hein
However, I think you are lookinf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2004 08:39 PM
08-09-2004 08:39 PM
Re: grep files
grep -e cond1 -e cond2 -e cond3 -e cond file*
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2004 01:19 AM
08-10-2004 01:19 AM
Re: grep files
Petr,
Please help me understand how your solution would solve the problem stated: an AND condition.
Regards,
Hein.