Regular expressions in tcsh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Regular expressions in tcsh script
# 1  
Old 02-12-2013
Regular expressions in tcsh script

Hi,

I have a shell script in tcsh to which I pass an argument, the length of which can vary. The possible values of the argument are the letters -c,s,i,q,a. and also a combination of these letters. (e.g: cs,si,ca,iq,qa,csq,acs,csia ..etc). The order of the letters does not matter.
My problem is to check the argument for any character other than these 5 and if any of the valid character appear more than one time (zero time is ok). The script should check both the conditions and throw an error. Is there any regular expression that I can use with if statement for this purpose?

Thanks
# 2  
Old 02-12-2013
you can do this with two regex check one after another
  • [csiqa]{1-5} for valid charecters
  • (.)(\1+) for duplicate charecters
# 3  
Old 02-12-2013
Shouldn't the two regex values be:
Code:
[csiqa]+
(.).*(\1+)

cant have more than 5 values without a duplicate anyway.

eg:
Code:
$ cat testfile
csiqa
csim
c
csiqsq
qq
csi
csii
$ grep -E '(.).*(\1+)' testfile
csiqsq
qq
csii
$ grep -Ev '^[csiqa]+$' testfile
csim

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Small script for website links and regular expressions

Need a help with a simple(i hope) script that would get a website location from stdin and then check all the links that site contains for some random regular expression ,and then save the links name and the expression found in some random file.Any help would be really helpfull. Considerin i`m... (5 Replies)
Discussion started by: Zbunce
5 Replies

2. 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

3. Shell Programming and Scripting

Help with regular expressions

I have a file that I'm trying to find all the cases of phone number extensions and deleting them. So input file looks like: abc x93825 def 13234 x52673 hello output looks like: abc def 13234 hello Basically delete lines that have 5 numbers following "x". I tried: x\(4) but it... (7 Replies)
Discussion started by: pxalpine
7 Replies

4. 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

5. Shell Programming and Scripting

Regular Expressions

#!/usr/bin/perl $word = "one last challenge"; if ( $word =~ /^(\w+).*\s(\w+)$/ ) { print "$1"; print "\n"; print "$2"; } The output shows that "$1" is with result one and "$2" is with result challenge. I am confused about how this pattern match expression works step by step. I... (8 Replies)
Discussion started by: DavidHe
8 Replies

6. UNIX for Dummies Questions & Answers

Regular expressions

In regular expressions with grep(or egrep), ^ works if we want something in starting of line..but what if we write ^^^ or ^ for pattern matching??..Hope u all r familiar with regular expressions for pattern matching.. (1 Reply)
Discussion started by: aadi_uni
1 Replies

7. Shell Programming and Scripting

regular expressions using perl script

i have a set of regular expressions. The words in the regular expression should be used to replace the i/p with hyphens '---'. i need perl script to evaluate these regular expression. the words in the regexes when found in the i/p file should be replaced with hyphens '---'. the set of regular... (3 Replies)
Discussion started by: Sgiri1
3 Replies

8. 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

9. 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

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