using regular expressions in c shell control structure


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using regular expressions in c shell control structure
# 1  
Old 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.
# 2  
Old 02-19-2006
Please read the Rules about homework assignments. Thanks.
# 3  
Old 02-20-2006
sorry. however, that piece of code is just 5% of my assignment as a whole. and i'm not posting my assignment and asking somebody to do it for me, i have something and i'm asking for advise on how to get it to work. i cant see how most ppl in here arent asking questions related to their assignments.
# 4  
Old 02-20-2006
Quote:
Originally Posted by ballazrus
sorry. however, that piece of code is just 5% of my assignment as a whole. and i'm not posting my assignment and asking somebody to do it for me, i have something and i'm asking for advise on how to get it to work. i cant see how most ppl in here arent asking questions related to their assignments.
....'cause the rules are eing enforced?
I don't know......

here's something to start with.......
Code:
#!/bin/ksh

a='AdeffedB'

if [[ $(expr  "$a" :  '^A[d-f][d-f]*B$') -ne 0 ]]; then
   echo 'found'
else
   echo 'NOT found'
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular Expressions

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

2. Shell Programming and Scripting

Regular Expressions

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

3. Shell Programming and Scripting

Regular Expressions in K Shell Script

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

4. Shell Programming and Scripting

Regular Expressions

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

5. UNIX for Dummies Questions & Answers

regular expressions

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

6. UNIX for Dummies Questions & Answers

Execute a shell script using regular expressions

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

7. Shell Programming and Scripting

regular expressions

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

8. Shell Programming and Scripting

Help with regular expressions

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

9. Shell Programming and Scripting

regular expressions

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

10. UNIX for Dummies Questions & Answers

Regular Expressions in shell scripts <yawn>

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
Login or Register to Ask a Question