-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
>>>>> "Vinu" == Vinu Balaji <[EMAIL PROTECTED]> writes:
>> grep [c]ron will search for the regex "[c]ron", which will only
>> match the string "cron". The regex will not match the string
>> "[c]ron".
>>
>> String "[c]ron" is not the same as Regex "[c]ron".
Vinu> #bash# grep '[c]ron' cron cron grep cron grep cron
Vinu> So the 'grep cron' is matched by the above command. So as
Vinu> per regular expression grep '[c]ron' and grep 'cron' are
Vinu> same.
I wouldn't go as far as to say that they're the same -- they just
match the same string. Here're another two examples if it makes
things clearer:
echo '[c]ron' | grep 'cron'
<no output>
echo '[c]ron' | grep '[c]ron'
<no output>
The first case is a simple string to string match. Since the two
strings '[c]ron' and 'cron' are not equal, grep does not output
anything.
The second case is matching a string '[c]ron' against the regex
'[c]ron'. However, the regex only matches the string 'cron', so again
grep produces no output.
A regex is only a template (or a pattern if you prefer) for matching
actual strings. There is no guarantee that the regex pattern with
match itself. If fact, it decidedly won't, unless no regex-special
characters are used.
(Exercise for the user -- create a regex using at least one special
character that will match itself: 1 point).
(Advanced exercise for the user: do the same, but without using . as
the special character: 10 points :) .
Talk on regular expressions in the next ILUG Delhi Meet?
Vinu> Oh and i got it that ps ax | grep '[c]ron' will search for
Vinu> 'cron' in the ps output and thus the grep always used to
Vinu> show only 'cron' when ps ax | grep '[c]ron' is executed.
Vinu> Only the ps output differs based on your command and thus it
Vinu> does not match.
Vinu> I think this is wat you meant but i could get it only after
Vinu> some thinking!
Good :)
Regards,
- -- Raju
- --
Raj Mathur [EMAIL PROTECTED] http://kandalaya.org/
GPG: 78D4 FC67 367F 40E2 0DD5 0FEF C968 D0EF CC68 D17F
It is the mind that moves
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>
iD8DBQFByTNvyWjQ78xo0X8RAgrwAJ9OWm9aT04lYlGNf3Cdrs9Uzu5YFACgkihU
4pg3Ise2CLr5pyDbLqcprWo=
=/WTs
-----END PGP SIGNATURE-----
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
_______________________________________________
linux-india-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-india-help