How to test for regular expression matches in tcsh?

How to test for regular expression matches in tcsh?

Post by Charlie Zende » Wed, 13 Oct 1999 04:00:00



Hi,

I have an tcsh application where I need to find whether or not
the hostname of the computer running the script, as stored in the
$HOST environment variable, ends with our local domain, "uci.edu".
I've tried

if ("$HOST" =~ "uci.edu") then
...
else if
...
endif

but this does not work.
Is there a way to use regular expressions with csh or tcsh?
I am using Redhat Linux 6.0.

Thanks,
Charlie
--

Earth System Science, University of California, Irvine CA 92697-3100

 
 
 

How to test for regular expression matches in tcsh?

Post by Eric Amic » Thu, 14 Oct 1999 04:00:00



> I have an tcsh application where I need to find whether or not
> the hostname of the computer running the script, as stored in the
> $HOST environment variable, ends with our local domain, "uci.edu".
> I've tried
> if ("$HOST" =~ "uci.edu") then
> ...
> else if
> ...
> endif

=~ uses filename patterns, not regular expressions.  Make it "*uci.edu"
(perhaps "*.uci.edu" would be better) instead.

--
Eric Amick
Columbia, MD


 
 
 

How to test for regular expression matches in tcsh?

Post by Charlie Zende » Thu, 14 Oct 1999 04:00:00


Quote:> =~ uses filename patterns, not regular expressions.  Make it "*uci.edu"
> (perhaps "*.uci.edu" would be better) instead.

This does not work either. Any other ideas? Here is what I tried

if ("$HOST" =~ "*uci.edu") then
    printf "ERROR: $HOST is in UCI domain\n"
else
    printf "ERROR: Unknown HOST domain in run script\n"
    exit
endif

There must be some feature of csh/tcsh that can do regexp matching.

Thanks,
Charlie
--

Earth System Science, University of California, Irvine CA 92697-3100

 
 
 

How to test for regular expression matches in tcsh?

Post by Philip Rowland » Thu, 14 Oct 1999 04:00:00



> This does not work either. Any other ideas? Here is what I tried

> if ("$HOST" =~ "*uci.edu") then
>     printf "ERROR: $HOST is in UCI domain\n"
> else
>     printf "ERROR: Unknown HOST domain in run script\n"
>     exit
> endif

Try
if ($HOST =~ *.uci.edu) then
etc.

Quote:> There must be some feature of csh/tcsh that can do regexp matching.

Why? If you really need full blown regexp matching, there is grep -q. Or
Perl.

--
Phil

 
 
 

How to test for regular expression matches in tcsh?

Post by Charlie Zende » Thu, 14 Oct 1999 04:00:00


OK, it works without the quotes, as in

if ($HOST =~ *uci.edu) then
     printf "$HOST is in UCI domain\n"
else
    printf "ERROR: Unknown HOST domain in run script\n"
    exit
endif

I did not know realize csh double quotes were that different from perl's.

Thanks,
Charlie
--

Earth System Science, University of California, Irvine CA 92697-3100

 
 
 

How to test for regular expression matches in tcsh?

Post by Ken Pizzi » Fri, 15 Oct 1999 04:00:00



>OK, it works without the quotes, as in

>if ($HOST =~ *uci.edu) then
>     printf "$HOST is in UCI domain\n"
>else
>    printf "ERROR: Unknown HOST domain in run script\n"
>    exit
>endif

>I did not know realize csh double quotes were that different from perl's.

They're as similar as apples and pineapples.

                --Ken Pizzini

 
 
 

1. Regular expression matching in sh

Hello,

Using standard Unix (*not* Linux) tools, how can I do regular expression
matching in sh. I'm trying to get something like:

"KeyWord:(.*) " and I want to store the content of (.*) in a variable. I can
do that fairly easily in Tcl or Perl but I can't use those tools.

To state my problem, I have to parse a file containing lines like

Bla BLA Bla KeyWord:value Bla Bla Bla

and extract the value after the keyword. So I'm grep'in for the value, then I
do a

for word in `grep Keyword filename`
do
        ExtractTheVaLue
        DoSomethingWithTheValue
done

Is there a better way?

Thanks,

L

--
Penguin Power!

Laurent Duperval
CGI - FWFM Project
Phone: (514) 350-3368

2. Keyboard input crashes Slackware Setup- **HELP**

3. regular expression matching in the second argument to RewriteRule?

4. netbsd-pmax

5. Regular Expression for Matching an IP address in a dotted notation

6. LILO & BusLogic 445s

7. Matching strings with regular expressions

8. 9 pin async/serial port (Gateway 2000 P5-90)

9. sed regular expressions matching

10. regular expressions in gawk funktion match

11. Matching words in regular expressions

12. Regular Expression matching

13. Which Regular Expression does not match subdirs ?