Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a problem producing filtering out hanzoMollusc (2)from my grep.

https://node.hanzo.com/production/application/ (1) 

https://node.hanzoMollusc.com/Messaging/Receiver (2)

My grep command is this for (2) which is working just fine.

/usr/xpg4/bin/grep -E 'node.hanzoMollusc.*Exception' diag* | grep -c 2013-03-28

Problem is if I wanted to search for (1) I need to modify the grep command a bit and use -F where its stated in the manual

"Matches using fixed strings. Treats  each pattern  specified as a string instead of a regular expression"

This is what I have come up so far... which is not working....

/usr/xpg4/bin/grep -F 'https://node.hanzo.com/application/*Exception' diag* | grep -c 2013-03-28

My problem lies in the domain part which is node.hanzo and node.hanzoMollusc that is why I didn't use -E on (1). Can anyone help me to fix this.

Edit

I was able to get what I want exactly with a few tweaks from Gilles example. Actually he was right I tried reading my question and it wasn't clear. My problem boils is this.

I have a problem filtering this

https://node.hanzoMollusc.com/Messaging/Receiver

everytime I use this command:

/usr/xpg4/bin/grep -E 'node.hanzoMollusc.*Exception' diag* | grep 2013-03-28

because it also shows up both node.hanzo and node.hanzoMollusc on the results.

I tweaked Gilles example and I was able to get the result right

/usr/xpg4/bin/grep -E '(https://node.hanzo.com/production/application)[/ ].*Exception' diag*

Thanks alot Gilles.

share|improve this question
    
Have you an example output you want to filter ? –  GHugo Mar 28 '13 at 7:59
    
grep -F will look for an actual asterisk character where you have a "*" in the search string. –  Johan Mar 28 '13 at 10:10
add comment

1 Answer

up vote 2 down vote accepted

It's not clear what you want to match: your examples are contradictory.

grep -F matches an exact string. If you put a * in the argument, it only matches a * character in the file.

If you want to allow matching several strings, use -E and the | operator. For example, the following command matches lines containing https://node.hanzo.com/production/application/somepath Exception Foo or https://node.hanzoMollusc.com/Messaging/Receiver/somepath Exception Foo (where the /somepath part is variable and can be omitted).

grep -E '(https://node.hanzo.com/production/application|node.hanzoMollusc.com/Messaging/Receiver)[/ ].*Exception' diag*
share|improve this answer
    
Sorry for the late comment, thanks alot for your help! –  dimas Apr 5 '13 at 1:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.