Re: comparing string with regular expression using test command in unix
Or grep. Paul Eggert wrote: N Gandhi Raja [EMAIL PROTECTED] writes: Can we use test command in UNIX to compare a *string *with the *regular expression*? No. You might look at 'expr' or 'awk' instead. ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils
Re: comparing string with regular expression using test command in unix
Hi, I want to compare a variable holding *string* with the *regular expression *. Is it possible to do in unix with a single command? Can we use test command in UNIX to compare a *string *with the *regular expression*? if so please provide an example for that. This sort of question generally implies that it would be well worth your investment in a good book on Unix shell programming. In coreutils, 'info expr' may prove enlightening. For example, $ foo=bar $ expr $foo : 'ba*' echo found || echo not found 2 found $ expr $foo : 'ca*' echo found || echo not found 0 not found Outside of the realm of coreutils, there are other techniques. For example, in /bin/sh, you can do glob matching (instead of regular expressions) like this: $ case $foo in ba*) echo found ;; *) echo not found ;; esac found Or use the regular expressions in sed: $ echo $foo | sed -ne '/ba*/p' bar $ echo $foo | sed -ne '/ca*/p' $ Or several other ideas. Hopefully this gives you some ideas. SASKEN BUSINESS DISCLAIMER This message may contain confidential, proprietary or legally Privileged information. In case you are not the original intended Recipient of the message, you must not, directly or indirectly, use, Disclose, distribute, print, or copy any part of this message and you are requested to delete it and inform the sender. Sorry, but this email is now in the public domain. You should consider using an account that does not have such unenforceable disclaimers when posting to public mailing lists. -- Eric Blake ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils
Re: comparing string with regular expression using test command in unix
N Gandhi Raja [EMAIL PROTECTED] writes: I want to compare a variable holding *string* with the *regular expression *. Is it possible to do in unix with a single command? Yes, with expr. $ info coreutils 'String expressions' Andreas. -- Andreas Schwab, SuSE Labs, [EMAIL PROTECTED] SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 And now for something completely different. ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils
Re: comparing string with regular expression using test command in unix
On Friday 17 February 2006 05:23, N Gandhi Raja wrote: I want to compare a variable holding *string* with the *regular expression *. Is it possible to do in unix with a single command? Can we use test command in UNIX to compare a *string *with the *regular expression*? if so please provide an example for that. `test` does not support regexes, but you can use either `expr` or bash-3.0+ supports regex comparison using the =~ operator -mike ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils
Re: comparing string with regular expression using test command in unix
N Gandhi Raja [EMAIL PROTECTED] writes: Can we use test command in UNIX to compare a *string *with the *regular expression*? No. You might look at 'expr' or 'awk' instead. ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils