LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Understand | (https://www.linuxquestions.org/questions/linux-general-1/understand-%7C-276233/)

tuananhbirm 01-10-2005 04:11 PM

Understand |
 
Hi, could any one tell me (pretty in detail) what the symbol "|" does besides indicates OR in creating a pattern ?
For example, what would happen if i type:
grep a * | grep b | grep c .....

?

Thanks a lot

tuananhbirm 01-10-2005 04:24 PM

And by the way, can anyone tell me the best way to write a regular expression to find all words contains a, b and c (in any order) ?

bulliver 01-10-2005 04:55 PM

'|' does not mean 'or', '||' means 'or'.

'|' is a pipe, which redirects the output from the command on the left, to input of the command on the right...

Quote:

For example, what would happen if i type:
grep a * | grep b | grep c
This will search every file in the current directory for lines with an 'a' in them, from these results it will search lines for 'b', and then for 'c'...so basically it will print every line from any file that has an 'a' _and_ a 'b' _and_ a 'c' in them.

tuananhbirm 01-10-2005 05:02 PM

Thanks for your reply !
Is there a better way to search for such pattern using regular expression ?

I came up with thing like:
grep -E (.*a.*b.*c.*|.*a.*c.*b.*|.*b.*a.*c.*|.*b.*c.*.a* ......) *

but it looked clumsy though.


All times are GMT -5. The time now is 05:17 AM.