- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- grep and "AND"
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
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
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-05-2003 12:46 PM
тАО08-05-2003 12:46 PM
am stuck with this for quite some time now. googling doesnt help.
let us say my file is like this
*****************************
#a
abcd
#abcd
abcd1
*******************************
i want to find out all occurances of abcd which doesnt have this comment.
i know this
grep -v ^# file | grep "abcd" file.
but is it possible to do this in a single grep.
something like this
grep -e (^#|abcd) file
will matach either of this pattern.
is there something will match both the pattern (the AND clause).
thanks for all the help. am stuck at this moment and bunnies for quick answers.
-balaji
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-05-2003 01:08 PM
тАО08-05-2003 01:08 PM
Re: grep and "AND"
output:
abcd
abcd1
worked for me in HP-UX?
What about Linux? Or do I not understand the question?
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-05-2003 01:16 PM
тАО08-05-2003 01:16 PM
Re: grep and "AND"
I got this to work:
grep "^abcd" file
but I don't think it is exactly what you are
looking for, as it will fail to find:
# abcd
SEP, the way you mentioned works but Balaji
is looking to do it with a single grep command.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-05-2003 01:35 PM
тАО08-05-2003 01:35 PM
Re: grep and "AND"
i am looking for that to be done in a single grep.
is there a way do it without piping in the output to grep.
-balaji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-05-2003 03:59 PM
тАО08-05-2003 03:59 PM
Solutiongrep "^[^#]bcd" file
The [^#] is basically saying "not #".
But the leading ^ (outside of the []'s) will say that it needs to be at the start of the line, but it also takes up a character space.
This brings us to some more regular expression fun:
grep "^[^#]*abcd" file
will match properly as requested. The * obviously meaning '0 or more' of the previous atom (character not # which is at the start of a string)...
yay.. fun.. Ok, so I started in one direction, found the proper one, and couldn't be bothered re-typing the response ;P
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-05-2003 05:20 PM
тАО08-05-2003 05:20 PM
Re: grep and "AND"
I always love Stuart's answers
grep "^[^#]bcd"
output
abcd
abcd1
I knew it wasn't so easy as my answer. It would be nice to know however why two greps are a problem. Overhead? Or just looking for an elegant solution.
Apologies for my misunderstanding. Feel free to zero point both posts.
:-)
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-06-2003 09:05 AM
тАО08-06-2003 09:05 AM
Re: grep and "AND"
cat file | grep ^abcd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-06-2003 05:57 PM
тАО08-06-2003 05:57 PM
Re: grep and "AND"
sed -n -e '/^#/d' -e '/abcd/p' < file
regards
Wouter