Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread 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.
Sponsored Links
  #2 (permalink)  
Old 02-19-2006
RTM's Avatar
RTM RTM is offline Forum Advisor  
Registered User
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,061
Please read the Rules about homework assignments. Thanks.
  #3 (permalink)  
Old 02-20-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.
  #4 (permalink)  
Old 02-20-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,199
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

Sponsored Links
Closed Thread

Bookmarks

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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 11:20 AM
regular expressions jack1981 Shell Programming and Scripting 4 07-12-2006 04:10 PM
Regular Expressions sandeep_hi Shell Programming and Scripting 6 06-12-2006 03:12 AM
Regular Expressions AresMedia Shell Programming and Scripting 1 08-22-2002 04:55 PM
Regular Expressions in shell scripts <yawn> sam_pointer UNIX for Dummies Questions & Answers 3 09-04-2001 06:30 PM



All times are GMT -4. The time now is 12:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0