Pattern search question in shell
I read a webpage - http://promberger.info/linux/2009/01...shell-scripts/
and would like to search functions which contains fromMessage and toMessage. Then I try the command Code:
cat target | grep \(from\|to\)Message Code:
cat target | grep (from|to)Message Code:
cat target | grep \[from\|to\]Message Code:
fromMessage Code:
fromMessage Below is the target file content: Code:
fromMessage Thanks for help. |
You need to quote parentheses from the shell and use egrep for alternatives and don't need cat:
egrep '(from|to)Message' target -- Well, you can use grep '\(from\|to\)Message' data but I don't recommend it. A lot easier to prefix 'e' or use the extended switch and be more standard at the same time. |
Quote:
Code:
$ grep -P "(from|to)Message" < target Code:
$ man grep |
Your first one is closest to working - try it as
Code:
grep "\(from\|to\)"Message target Better is to use egrep and avoid the escapes altogether - Code:
grep -E "(from|to)"Message target |
Try this
cat target | egrep "(from|to)"Message |
Quote:
Code:
egrep '(from)|(to)Message' target |
That would also match 'from', if it was in the data, though.
|
Quote:
Code:
egrep '((from)|(to))Message' target |
Sure thing. :) But
Code:
egrep '(from|to)Message' target |
Quote:
|
I read the manual and at the moment using
Code:
grep -E '(from|to)'Message text.txt Thanks all your help. Those information are really helpful. I appreciate it.: ) |
All times are GMT -5. The time now is 04:29 PM. |