The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Execute a shell script using regular expressions supergirl3954 UNIX for Dummies Questions & Answers 1 02-28-2008 07:20 AM
regular expressions jack1981 Shell Programming and Scripting 4 07-12-2006 12:10 PM
Regular Expressions sandeep_hi Shell Programming and Scripting 6 06-11-2006 11:12 PM
Regular Expressions AresMedia Shell Programming and Scripting 1 08-22-2002 12:55 PM
Regular Expressions in shell scripts <yawn> sam_pointer UNIX for Dummies Questions & Answers 3 09-04-2001 02:30 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-18-2006
Registered User
 

Join Date: Feb 2006
Posts: 10
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.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-19-2006
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Please read the Rules about homework assignments. Thanks.
Reply With Quote
  #3 (permalink)  
Old 02-19-2006
Registered User
 

Join Date: Feb 2006
Posts: 10
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.
Reply With Quote
  #4 (permalink)  
Old 02-19-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
regex, regular expressions

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:58 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0