- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- want to grep lines which is having multiple string...
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
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
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
тАО04-30-2006 04:28 PM
тАО04-30-2006 04:28 PM
want to grep lines which is having multiple strings pattern
I want to grep lines which is having multiple strings pattern.
Suppose I have some files, I want to find lines which contain two words like "Ezhil" and "Arasan".
grep -i "Ezhil" *.txt --> gives all the lines ( with filename ) which contan this pattern.
I do not want all these lines, wanted to see only lines with AND another word "Arasan".
what command syntax will help for this ?
Thanks
Ezhil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-30-2006 04:41 PM
тАО04-30-2006 04:41 PM
Re: want to grep lines which is having multiple strings pattern
Try this
grep -i "Ezhil" *.txt |grep -i Arasan
this will give you lines which have both Ezhil and Arasan...take care of -i for case sensitivity..
Cheers
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-30-2006 10:42 PM
тАО04-30-2006 10:42 PM
Re: want to grep lines which is having multiple strings pattern
grep Eizhil *.txt | grep Arasan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-30-2006 10:59 PM
тАО04-30-2006 10:59 PM
Re: want to grep lines which is having multiple strings pattern
# perl -ne'/Ezhil/&&/Arasan/ and print' *.txt
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-01-2006 01:16 AM
тАО05-01-2006 01:16 AM
Re: want to grep lines which is having multiple strings pattern
>> perl -ne'/Ezhil/&&/Arasan/ and print' *.txt
And without the case-insensitive requirement suggested, and without having to print the file name as requested an awk solution it is a touch easier still:
awk '/Ezhil/&&/Arasan/' *.txt
However, to fullfill all the requirements I think you'd need:
awk 'BEGIN {IGNORECASE=1} /Ezhil/&&/Arasan/ { print FILENAME ":" $0}' *.txt
So in general, I'd just stick to the multiple greps as suggested.
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-01-2006 01:26 AM
тАО05-01-2006 01:26 AM
Re: want to grep lines which is having multiple strings pattern
# perl -ne'/Ezhil/&&/Arasan/ and print"$ARGV:$_"' *.txt
And case insensitiviness
# perl -ne'/Ezhil/i&&/Arasan/i and print"$ARGV:$_"' *.txt
And also word only (GNU grep supports -w for that, but a lot of other grep versions do not):
# perl -ne'/\bEzhil\b/i&&/\bArasan\b/i and print"$ARGV:$_"' *.txt
So using GNU grep case-insensitive
# grep -w -i ezhil *.txt | grep -w -i arasan
One small problem left there, if there is only one .txt file, in which case the file name is NOT prepended to the output. You can force that by grepping /dev/null:
# grep -w -i ezhil *.txt /dev/null | grep -w -i arasan
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-01-2006 01:30 AM
тАО05-01-2006 01:30 AM
Re: want to grep lines which is having multiple strings pattern
...but adding case-insensitive matching to the perl offering is *so easy* :-))
# perl -ne' /Ezhil/i && /Arasan/i and print' *.txt
Regards!
...JRF...