testing for regex at command line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers testing for regex at command line
# 1  
Old 10-08-2008
testing for regex at command line

hi unixers,

i wonder if someone can tell me how i can check for a regex at the command line?


Code:
if any parameter begins with a special character then
   do this
else
   do that

thanks for your help.
# 2  
Old 10-08-2008
since i'm still at the top of the list, i thought i would add that i'm using ksh.

thanks for your help.
# 3  
Old 10-08-2008
Testing a parameter at the command line? Be preciser and clarify what your trying to achieve.

Regards
# 4  
Old 10-08-2008
sorry about that and thanks for your response Franklin52.

i have a script that has this syntax: script <group_id> <user_name> <regex>

rules:
* the user can enter single or multiple group_ids and/or user_names
* the regex is optional
* group_ids are 5-digit integers
* user_names are can be a combo of chars and integers


because the regex parameter is optional, i want to check if it was added at the command line. further, if the regex was actually added, then i want to use that regex value against a different script that i created:


Code:
if any parameter begins with a special character; then
  run a different script with the regex parameter
else
  do something else
fi

here's as far as i got.. and i admit, it's not far....


Code:
if [ "$*" begins with any of these '[][\\.*$^]/\\&' ]
  ./script2 regex
else
  do something else
fi

thanks
# 5  
Old 10-08-2008
Using getopts would be a better bet imho.
-g group, -u user -r (optional regexp)...that kind of thing.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need regex for line not starting with hash #

I need to search for lines starting with "Include" and later has string "httpd-ssl.conf" like the regex should return match for "Include conf/extra/httpd-ssl.conf" I tried the following: ^]*#;].+Include.*httpd-ssl.conf Below is my current file: # Secure (SSL/TLS) connections... (7 Replies)
Discussion started by: mohtashims
7 Replies

2. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies

3. Shell Programming and Scripting

Regex to include up to blank line.

Hi guys I am trying to figure out how to match a pattern with a regex up to a full blank line. I will show you what I mean with this example: example A movie name: ted movie name: TMNT movie name: Jinxed example B movie names: Gravity Faster Turbo song titles: dont hello problem (8 Replies)
Discussion started by: acoding
8 Replies

4. Shell Programming and Scripting

Using regex's from file1, print line and line after matches in file2

Good day, I have a list of regular expressions in file1. For each match in file2, print the containing line and the line after. file1: file2: Output: I can match a regex and print the line and line after awk '{lines = $0} /Macrosiphum_rosae/ {print lines ; print lines } ' ... (1 Reply)
Discussion started by: pathunkathunk
1 Replies

5. UNIX for Dummies Questions & Answers

read regex from ID file, print regex and line below from source file

I have a file of protein sequences with headers (my source file). Based on a list of IDs (which are included in some of the headers), I'd like to print out only the specified sequences, with only the ID as header. In other words, I'd like to search source.txt for the terms in IDs.txt, and print... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

6. UNIX for Dummies Questions & Answers

How to specify beginning-of-line/end-of-line characters inside a regex range

How can I specify special meaning characters like ^ or $ inside a regex range. e.g Suppose I want to search for a string that either starts with '|' character or begins with start-of-line character. I tried the following but it does not work: sed 's/\(\)/<do something here>/g' file1 ... (3 Replies)
Discussion started by: jawsnnn
3 Replies

7. UNIX for Dummies Questions & Answers

Regex for beginning of line until a comma

What is a regex for "the dalai lama, his holiness the" that would just grab "the dalai lama" and one that would just grab "his holiness the"? Both should exclude the comma.. I was trying '^.*' and many variants with no luck. (6 Replies)
Discussion started by: glev2005
6 Replies

8. Shell Programming and Scripting

Stress testing php files at Unix/Linux Command line

Hi, Your great help is very appreciated. I am looking for any Unix command or tool for doing Stress/Load test of php files at command prompt. I tried torture.pl but it is not working after20 concurrent threads/users. as it is very urgent for me..please suggest ur ideas asap. thanks (5 Replies)
Discussion started by: Malleswari
5 Replies

9. UNIX for Dummies Questions & Answers

replace line after a regex

Hi, I am trying to write a script which will modify a given account's settings by searching for a line in a file and then replacing the line after it. Here is a portion of my input file: type=friend username=0002 secret=password host=dynamic dtmfmode=rfc2833 mailbox=0002 context=sip... (2 Replies)
Discussion started by: the1armedcoder
2 Replies

10. Shell Programming and Scripting

sed: delete regex line and next line if blank

Hi, I want to write a sed script which from batiato: batiato/giubbe: pip_b.2.txt pip_b.3.txt pip_b.3mmm.txt bennato: bennato/peterpan: 123.txt consoli: pip_a.12.txt daniele: (2 Replies)
Discussion started by: one71
2 Replies
Login or Register to Ask a Question