Sponsored Content
Top Forums Shell Programming and Scripting Check if argument passed is an integers Post 31338 by Vishnu on Wednesday 6th of November 2002 09:12:51 AM
Old 11-06-2002
That was a wrong claim... try this on command line...
echo +2345 | grep -E '^(\+|-)?[0-9]+$'

I hope you understood what '^(\+|-)?[0-9]+$' means...

Since you seem concerned with selective and intelligent matches, I would suggest you to go through some good book on regular expressions...

here is one worth it's bucks...

http://www.oreilly.com/catalog/regex2/

Cheers!
Vishnu.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to print all argument passed

like i have script with which i have passed arg list :eg: i/p: scriopt1 arg1 arg2 arg3 .... argn o/p: arg1 arg2 arg3 .... argn (2 Replies)
Discussion started by: RahulJoshi
2 Replies

2. Shell Programming and Scripting

How to check that passed parameters all have the same extension?

$ ls monkey.txt banana.csv tree.txt $ myscript monkey.txt tree.txt All extensions ARE alike. $ myscript *txt All extensions ARE alike. $ myscript monkey.txt banana.csv All extensions are NOT alike. $ myscript * All extensions are NOT alike. My brain has given up; what's the simplest... (11 Replies)
Discussion started by: cs03dmj
11 Replies

3. Shell Programming and Scripting

File not recognized when passed as argument

I have the below script in file read_file.ksh if ] || ] then echo "Required one input file" echo "Enter a file to get char count:" read $FILE_NAME if ] then echo "valid file" else echo "Not a valid file." fi When run as read_file.ksh detail.csv or... (9 Replies)
Discussion started by: michaelrozar17
9 Replies

4. Shell Programming and Scripting

Check if passed arguments is users

i want to check passed arguments one by one and if it is user print home director of that user (3 Replies)
Discussion started by: testman84
3 Replies

5. Shell Programming and Scripting

shell script for ftp files passed in command line argument

i want to write a shell script function that will ftp the files passed in the command line . i have written a shell script for ftp but how will it do for all files passed in command line argument , i am passing 4 files as argument ./ftp.sh file1 file2 file3 file4 code written by me... (5 Replies)
Discussion started by: rateeshkumar
5 Replies

6. Shell Programming and Scripting

Shell script that check the argument passed to it and prints error if test condition is not met

I want to make a script that check for the argument passed to it and generates an error in case any character/string argument passed to it. I am using below code, but its not working. can anyone help. #!/bin/bash if ]; then echo 'An integer argument is passed to the script hence... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

7. Shell Programming and Scripting

Variable passed as argument

I have a script. #!/bin/sh cur_$1_modify_time=Hello echo "cur_$1_modify_time" When I run like sh /root/script1 jj I expect value "Hello" being assigned to variable "cur_jj_modify_time" and output being "Hello" ie echoing $cur_jj_modify_time But the output comes as # sh... (3 Replies)
Discussion started by: anil510
3 Replies

8. Shell Programming and Scripting

Grep float/integers but skip some integers

Hi, I am working in bash in Mac OSX, I have following 'input.txt' file: <INFO> HypoTestTool: >>> Done running HypoTestInverter on the workspace combined <INFO> HypoTestTool: The computed upper limit is: 11 +/- 1.02651 <INFO> HypoTestTool: expected limit (median) 11 <INFO> HypoTestTool: ... (13 Replies)
Discussion started by: Asif Siddique
13 Replies

9. How to Post in the The UNIX and Linux Forums

Read a json file passed as cmd line argument

usage: myscript.sh config.json config.json: { "HOST":"abc", "DB_NM":"xyz", "USR_NM":"asd", "PWD":"xxx", ......... ......... ......... ........ } myscript.sh: (2 Replies)
Discussion started by: RGRT
2 Replies

10. Shell Programming and Scripting

Getting number of argument passed to a shell script

Hi Experts, I have been trying to work on a simple shell script that will just add the two argument passed to it. Here is what i tried : #!/bin/bash welcome(){ echo "Welcome to this Progg. which will accept two parameter" } main_logic(){ arg=$# echo "Number of argument passed is... (4 Replies)
Discussion started by: mukulverma2408
4 Replies
Regexp::Optimizer(3pm)					User Contributed Perl Documentation				    Regexp::Optimizer(3pm)

NAME
Regexp::Optimizer - optimizes regular expressions SYNOPSIS
use Regexp::Optimizer; my $o = Regexp::Optimizer->new; my $re = $o->optimize(qr/foobar|fooxar|foozap/); # $re is now qr/foo(?:[bx]ar|zap)/ ABSTRACT
This module does, ahem, attempts to, optimize regular expressions. INSTALLATION
To install this module type the following: perl Makefile.PL make make test make install DESCRIPTION
Here is a quote from perltodo. Factoring out common suffices/prefices in regexps (trie optimization) Currently, the user has to optimize "foo|far" and "foo|goo" into "f(?:oo|ar)" and "[fg]oo" by hand; this could be done automatically. This module implements just that. EXPORT Since this is an OO module there is no symbol exported. METHODS
This module is implemented as a subclass of Regexp::List. For methods not listed here, see Regexp::List. $o = Regexp::Optimizer->new; $o->set(key => value, ...) Just the same us Regexp::List except for the attribute below; unexpand When set to one, $o->optimize() tries to $o->expand before actually starting the operation. # cases you need to set expand => 1 $o->set(expand => 1)->optimize(qr/ foobar| fooxar| foozar /x); $re = $o->optimize(regexp); Does the job. Note that unlike "->list2re()" in Regexp::List, the argument is the regular expression itself. What it basically does is to find groups will alterations and replace it with the result of "$o->list2re". $re = $o->list2re(list of words ...) Same as "list2re()" in Regexp::List in terms of functionality but how it tokenize "atoms" is different since the arguments can be regular expressions, not just strings. Here is a brief example. my @expr = qw/foobar fooba+/; Regexp::List->new->list2re(@expr) eq qr/fooba[+r]/; Regexp::Optimizer->new->list2re(@expr) eq qr/foob(?:a+ar)/; CAVEATS
This module is still experimental. Do not assume that the result is the same as the unoptimized version. o When you just want a regular expression which matches normal words with not metacharacters, use <Regexp::List>. It's more robus and much faster. o When you have a list of regular expessions which you want to aggregate, use "list2re" of THIS MODULE. o Use "->optimize()" when and only when you already have a big regular expression with alterations therein. "->optimize()" does support nested groups but its parser is not tested very well. BUGS
o Regex parser in this module (which itself is implemented by regular expression) is not as thoroughly tested as Regexp::List o May still fall into deep recursion when you attempt to optimize deeply nested regexp. See "PRACTICALITY". o Does not grok (?{expression}) and (?(cond)yes|no) constructs yet o You need to escape characters in character classes. $o->optimize(qr/[a-z()]|[A-Z]/); # wrong $o->optimize(qr/[a-z()]|[A-Z]/); # right $o->optimize(qr/[0-9A-Za-z]|[Q-_.!~*"'()E]/ # right, too. o When character(?: class(?:es)?)? are aggregated, duplicate ranges are left as is. Though functionally OK, it is cosmetically ugly. $o->optimize(qr/[0-5]|[5-9]|0123456789/); # simply turns into [0-5][5-9]0123456789] not [0-9] I left it that way because marking-rearranging approach can result a humongous result when unicode characters are concerned (and p{Properties}). PRACTICALITY
Though this module is still experimental, It is still good enough even for such deeply nested regexes as the followng. # See 3.2.2 of http://www.ietf.org/rfc/rfc2616.txt # BNF faithfully turned into a regex http://(?:(?:(?:(?:(?:[a-z]|[A-Z])|[0-9])|(?:(?:[a-z]|[A-Z])|[0-9])(?:(?:(?:[a-z]|[A-Z])|[0-9])|-)*(?:(?:[a-z]|[A-Z])|[0-9])).)*(?:(?:[a-z]|[A-Z])|(?:[a-z]|[A-Z])(?:(?:(?:[a-z]|[A-Z])|[0-9])|-)*(?:(?:[a-z]|[A-Z])|[0-9])).?|[0-9]+.[0-9]+.[0-9]+.[0-9]+)(?::[0-9]*)?(?:/(?:(?:(?:(?:[a-z]|[A-Z])|[0-9])|[-\_.!~*'()])|%(?:[0-9]|[A-Fa-f])(?:[0-9]|[A-Fa-f])|[:@&=+$,])*(?:;(?:(?:(?:(?:[a-z]|[A-Z])|[0-9])|[-\_.!~*'()])|%(?:[0-9]|[A-Fa-f])(?:[0-9]|[A-Fa-f])|[:@&=+$,])*)*(?:/(?:(?:(?:(?:[a-z]|[A-Z])|[0-9])|[-\_.!~*'()])|%(?:[0-9]|[A-Fa-f])(?:[0-9]|[A-Fa-f])|[:@&=+$,])*(?:;(?:(?:(?:(?:[a-z]|[A-Z])|[0-9])|[-\_.!~*'()])|%(?:[0-9]|[A-Fa-f])(?:[0-9]|[A-Fa-f])|[:@&=+$,])*)*)*(?:\?(?:[;/?:@&=+$,]|(?:(?:(?:[a-z]|[A-Z])|[0-9])|[-\_.!~*'()])|%(?:[0-9]|[A-Fa-f])(?:[0-9]|[A-Fa-f]))*)?)? # and optimized http://(?::?[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?.[a-zA-Z]*(?:[a-zA-Z0-9-]*[a-zA-Z0-9])?.?|[0-9]+.[0-9]+.[0-9]+.[0-9]+)(?::[0-9]*)?(?:/(?:(?:(?:[a-zA-Z0-9-\_.!~*'x28x29]|%[0-9A-Fa-f][0-9A-Fa-f])|[:@&=+$,]))*(?:;(?:(?:(?:[a-zA-Z0-9-\_.!~*'x28x29]|%[0-9A-Fa-f][0-9A-Fa-f])|[:@&=+$,]))*)*(?:/(?:(?:(?:[a-zA-Z0-9-\_.!~*'x28x29]|%[0-9A-Fa-f][0-9A-Fa-f])|[:@&=+$,]))*(?:;(?:(?:(?:[a-zA-Z0-9-\_.!~*'x28x29]|%[0-9A-Fa-f][0-9A-Fa-f])|[:@&=+$,]))*)*)*(?:\?(?:(?:[;/?:@&=+$,a-zA-Z0-9-\_.!~*'x28x29]|%[0-9A-Fa-f][0-9A-Fa-f]))*)?)? By carefully examine both you can find that character classes are properly aggregated. SEE ALSO
Regexp::List -- upon which this module is based "eg/" directory in this package contains example scripts. Perl standard documents L<perltodo>, L<perlre> CPAN Modules Regexp::Presuf, Text::Trie Books Mastering Regular Expressions <http://www.oreilly.com/catalog/regex2/> AUTHOR
Dan Kogai <dankogai@dan.co.jp> COPYRIGHT AND LICENSE
Copyright 2003 by Dan Kogai This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2004-12-05 Regexp::Optimizer(3pm)
All times are GMT -4. The time now is 01:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy