Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep and the infix operator

Status
Not open for further replies.

tomdagliusa

Programmer
May 31, 2000
34
US
The grep man page states: Two regular expressions may be joined by the infix opera­tor |; the resulting regular expression matches any string matching either subexpression.

I searched this site and didn't find anything, nor could I understand how to use, or what is the infix operator | (which to me just looks like an or). SO, let's say I have some command which works: someCommand | grep "Server"
and that gives me the lines with "Server" in them.
I can also do: someCommand | grep "\-pc"
and that gives me the lines with -pc in them.

How do I OR the two together, i.e. this infix thingy?

Thanks,
Tom
 
Try

someCommand | grep -E "Server|\-pc"


 
Hi,
yes the '|' is the OR bar.

Command | egrep "this|that|theotherthing"

Make sure not use spaces in your egrep exepression around the OR Bar unless you want to search for spaces.

Also the Quotes ( "" or '' ) are required or the SH will think you meant another command.

without the quotes this and theotherthng would be though of as commands. the shell would expand the above to

Command | egrep this | that | theotherthing

without the quotes.

InFix means the operator is in the middle.

2 + 3

Post Fix means the operator comes at the end.

3 2 +

PreFix means the operator comes at the beginning.

+ 3 4




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top