02-18-2006
using regular expressions in c shell control structure
i cant get around using regular expressions in if/else statements. it simply doesnt give me the right results.
i've tried using switch/case but that is just as sh!tty as well. (pardon my french but im getting frustrated with c shell..only reason why im writing in it is because it's a hwk assignment to compare bourne with c shell)
anyways
im trying to write a regular expression that says a string must begin with A have any number of [d-f] in between and end with B
so what i got is basically this..
=========
echo -n "Enter a string: "
set $string = $<
if ($string =~ '^A[d-f]*B$') then
echo "accepted"
else
echo "rejected"
endif
exit
==========
it simply doesnt work
cshell doesnt seem to like the anchors or other special characters.
any feedback would be greatly appreciated.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Quite possibly a simple problem who's answer is evading me:
I am trying to write a sh shell script, part of which is *logically* trying to do the following:
if ]; then
...
fi
if ]; then
...
else
...
fi
Where the 1st condition is looking for a hostname passed as $1, the second... (3 Replies)
Discussion started by: sam_pointer
3 Replies
2. Shell Programming and Scripting
Hi,
can anyone advise me how to shorten this:
if || ; then
I tried but it dosent seem to work, whats the correct way.
Cheers (4 Replies)
Discussion started by: jack1981
4 Replies
3. Shell Programming and Scripting
I have following content in the file
CancelPolicyMultiLingual3=U|PC3|EN
RestaurantInfoCode1=U|restID1|1
.....
I am trying to use following matching extression
\|(+)
to get this
PC3|EN
restID1|1
Obviously it does not work.
Any ideas? (13 Replies)
Discussion started by: arushunter
13 Replies
4. Shell Programming and Scripting
Hello,
Let say I have a string with content "Free 100%". How can extract only "100" using ksh? I would this machanism to work if instead of "100" there is any kind of combination of numbers(ex. "32", "1238", "1"). I want to get only the digits.
I have written something like this:
... (4 Replies)
Discussion started by: whatever
4 Replies
5. UNIX for Dummies Questions & Answers
I am have a configuration script that my shell script uses. There is a regular expression defined for the input file. How do execute the shell script and pass the name of the input file using a regular expression.
I would greatly appreciate some help. If you could point my to a website that... (1 Reply)
Discussion started by: supergirl3954
1 Replies
6. UNIX for Dummies Questions & Answers
how to find for a file whose name has all characters in uppercase after 'project'?
I tried this:
find . -name 'project**.pdf'
./projectABC.pdf
./projectABC123.pdf
I want only ./projectABC.pdf
What is the regular expression that correponds to "all characters are capital"?
thanks (8 Replies)
Discussion started by: melanie_pfefer
8 Replies
7. Shell Programming and Scripting
what elements does " /^/ " match?
I did the test which indicates that it matches single lowercase character like 'a','b' etc. and '1','2' etc.
But I really confused with that. Because, "/^abc/" matches strings like "abcedf" or "abcddddee".
So, what does caret ^ really mean?
Any response... (2 Replies)
Discussion started by: DavidHe
2 Replies
8. Shell Programming and Scripting
I need to write a K shell script to find full file names , line numbers and lines which have words meeting either of following 2 criterias -
1)words which are 6 to 8 character long and alphanumeric.
2)Minimum 8 characters, one upper case, one lower case letter, one of the special characters... (1 Reply)
Discussion started by: Rajpreet1985
1 Replies
9. Shell Programming and Scripting
I am new to shell scripts.Can u please help me on this req.
test_user = "Arun"
if
echo "test_user is a word"
else
echo "test_user is not a word" (1 Reply)
Discussion started by: chandrababu
1 Replies
10. Shell Programming and Scripting
Hi
Ilove unix and alwyas trying to to learn unix,but i am weak in using regular expressions.can you please give me a littel brief discription that how can i understand them and how to use .your response could lead a great hand in my unix love. (1 Reply)
Discussion started by: manoj attri
1 Replies
LEARN ABOUT SUNOS
re_exec
re_comp(3C) Standard C Library Functions re_comp(3C)
NAME
re_comp, re_exec - compile and execute regular expressions
SYNOPSIS
#include <re_comp.h>
char *re_comp(const char *string);
int re_exec(const char *string);
DESCRIPTION
The re_comp() function converts a regular expression string (RE) into an internal form suitable for pattern matching. The re_exec() func-
tion compares the string pointed to by the string argument with the last regular expression passed to re_comp().
If re_comp() is called with a null pointer argument, the current regular expression remains unchanged.
Strings passed to both re_comp() and re_exec() must be terminated by a null byte, and may include NEWLINE characters.
The re_comp() and re_exec() functions support simple regular expressions, which are defined on the regexp(5) manual page. The regular
expressions of the form {m}, {m,}, or {m,n} are not supported.
RETURN VALUES
The re_comp() function returns a null pointer when the string pointed to by the string argument is successfully converted. Otherwise, a
pointer to one of the following error message strings is returned:
No previous regular expression
Regular expression too long
unmatched (
missing ]
too many () pairs
unmatched )
Upon successful completion, re_exec() returns 1 if string matches the last compiled regular expression. Otherwise, re_exec() returns 0 if
string fails to match the last compiled regular expression, and -1 if the compiled regular expression is invalid (indicating an internal
error).
ERRORS
No errors are defined.
USAGE
For portability to implementations conforming to X/Open standards prior to SUS, regcomp(3C) and regexec(3C) are preferred to these func-
tions. See standards(5).
SEE ALSO
grep(1), regcmp(1), regcmp(3C), regcomp(3C), regexec(3C), regexpr(3GEN), regexp(5), standards(5)
SunOS 5.10 26 Feb 1997 re_comp(3C)