Regular expression as parameter

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Regular expression as parameter
# 1  
Old 10-22-2009
Wrench Regular expression as parameter

Hello everybody, I have a problem with creating a script which allows a single parameter to be passed. Sorry if I'm not expert, I'm new at this and .

The code is

if [ "$1" = "" ]; then
        echo "Something"
...does other things...
echo "Found $COUNT users"

There are two errors:
1) the grep $1 is not correctly interpreted because the expanded command doesn't have the ' delimitator.

2) There must be some error on the COUNT assignment too, because it doesn't write out the no of lines in the file.

I tried with ksh and bash shell, but it doesn't seem to be a shell type problem.
I know i'm really at the basics, but some help would be very appreciated Smilie

Last edited by Franklin52; 10-22-2009 at 02:50 PM.. Reason: Replaced quote tags with code tags
# 2  
Old 10-22-2009
you could add

set -x

to the beginning of your code to get some debug output. I'm not seeing anything obviously wrong with your code so more information would be needed.
# 3  
Old 10-22-2009
grep -i "$1" $TEMPUSERS > $USERSFILE

The "" stops the interpretation of special characters.


Otherwise the filename gets printed as well.

Last edited by Scrutinizer; 10-22-2009 at 04:37 PM..
# 4  
Old 10-23-2009
Thank you for the help on the count, now it works Smilie

As for the grep with the parameter, i resolved using egrep.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular expression

Hello Gurus, I am looking for regular expressions for awk to filter on second column 2nd and 3rd digit Using in code something like: awk '{if ( $2 == "0::" ) print} source file: 0 0:0:0 FC 15 normal 559104 51200 0:3:1* 1:3:1 600 1 0:0:1 FC 15 normal ... (2 Replies)
Discussion started by: vishalgoyal
2 Replies

2. Shell Programming and Scripting

Regular expression

Can someone please explain me what does this mean? ^{1,50}$ (1 Reply)
Discussion started by: Anupam_Halder
1 Replies

3. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

4. Programming

How to use regular expression in C/C++ ?

how to code with regexp.h some one can give me instance? thx (4 Replies)
Discussion started by: AKB48
4 Replies

5. UNIX for Dummies Questions & Answers

Parameter Expansion with regular expression

Hello experts, I am exploring parameter expansion, and trying to cut the fields in a URL. Following is the requirement: I have // abc.nnt /dir1/dir2/dir3/dir4/ What i need to get is the path after dir3, and dir3 will be passed. output that i need is... (1 Reply)
Discussion started by: gjarms
1 Replies

6. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

7. Shell Programming and Scripting

Passing in regular expression as a parameter to sed

Hi All, Im using Bash. I have a pipe delimited config file which contains 3 columns, 1st column = location of a file to be chnaged 2 column = expression to find within file 3rd column = string to replace. A script will loop through the contetnts of this file and apply the changes using... (2 Replies)
Discussion started by: satnamx
2 Replies

8. Shell Programming and Scripting

Integer expression expected: with regular expression

CA_RELEASE has a value of 6. I need to check if that this is a numeric value. if not error. source $CA_VERSION_DATA if * ] then echo "CA_RELESE $CA_RELEASE is invalid" exit -1 fi + source /etc/ncgl/ca_version_data ++ CA_PRODUCT_ID=samxts ++ CA_RELEASE=6 ++ CA_WEEK_NO=7 ++... (3 Replies)
Discussion started by: ketkee1985
3 Replies

9. Linux

Regular expression to extract "y" from "abc/x.y.z" .... i need regular expression

Regular expression to extract "y" from "abc/x.y.z" (2 Replies)
Discussion started by: rag84dec
2 Replies

10. Shell Programming and Scripting

Regular Expression + Aritmetical Expression

Is it possible to combine a regular expression with a aritmetical expression? For example, taking a 8-numbers caracter sequece and casting each output of a grep, comparing to a constant. THX! (2 Replies)
Discussion started by: Z0mby
2 Replies
Login or Register to Ask a Question