1 |
On Sat, 2005-12-24 at 11:58 -0800, J.A. wrote: |
2 |
> Any regex containing ! or | operators seem to get |
3 |
> interpreted by bash as a bash operator. This could |
4 |
> be avoided by putting the regex into a (perl?) file |
5 |
> but then I would have to memorize a bunch of stupid |
6 |
> little file scripts or create a stupid little file |
7 |
> containing the script every time. |
8 |
> |
9 |
> Here is one little example that doesn't work: |
10 |
> |
11 |
> # Filter everything except lines containing |
12 |
> # token1 or token2 |
13 |
> locate something | grep token1|token2 |
14 |
> |
15 |
> # Do not display lines with token3: |
16 |
> locate something | grep !token3 |
17 |
> |
18 |
> grep has a -v option which is the same as a regex |
19 |
> !token3 but I can't figure out how to then get grep |
20 |
> to recognize inverting more than one token such as |
21 |
> !(token3|token4). |
22 |
|
23 |
! and | are bash operators, you need to escape them unless they are |
24 |
inside single-quotes. IIRC double quotes are interpeted by most shells, |
25 |
and single quotes arn't. |
26 |
|
27 |
# whatever | egrep 'token1|token2' |
28 |
or # whatever |egrep token1\|token2 |
29 |
|
30 |
# whatever | grep \!token |
31 |
or # whatever |grep '!token' |
32 |
|
33 |
I like egrep over grep. I like regexp. |
34 |
|
35 |
-Lares |
36 |
|
37 |
-- |
38 |
Lares Moreau <lares.moreau@×××××.com> | LRU: 400755 http://counter.li.org |
39 |
lares/irc.freenode.net | |
40 |
Gentoo x86 Arch Tester | ::0 Alberta, Canada |
41 |
Public Key: 0D46BB6E @ subkeys.pgp.net | Encrypted Mail Preferred |
42 |
Key fingerprint = 0CA3 E40D F897 7709 3628 C5D4 7D94 483E 0D46 BB6E |