Validate numerical


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Validate numerical
# 1  
Old 11-21-2014
Variation to Akshay's shell suggestion:
Code:
isnum() { printf %f "${1:-NaN}" >/dev/null 2>&1;}

This User Gave Thanks to Scrutinizer For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script regarding non numerical or empty value

Hello Team, I need bash script to check if my output is non numerical or empty. if its then my output should display default value as 0 basically, I am reading value from txt file. most of numerical value, in case there is no numerical value or its empty, then my output should be 0. ... (5 Replies)
Discussion started by: ghpradeep
5 Replies

2. UNIX for Dummies Questions & Answers

How to use grep with numerical values?

I'm new to Unix and I have been trying to fix this problem for the past week. How would I use grep to display only certain numbers for a list. For example, if I have this list: Joe senior 4/50 John junior 25/50 Mary junior 41/50 Martha sophomore 2/50 ...How do I get a file... (1 Reply)
Discussion started by: PTcharger
1 Replies

3. UNIX for Dummies Questions & Answers

List files according to the numerical value

Hi, I have a large number of files which are named as follows. VF_50, VF_100, VF_150, VF_250, VF_300, VF_350, VF_400, VF_450, VF_500. When I do an 'ls' it arranges the files in the following way VF_100, VF_150, VF_250, VF_300, VF_350, VF_400, VF_450, VF_50, VF_500. Is there a way to... (2 Replies)
Discussion started by: lost.identity
2 Replies

4. UNIX for Dummies Questions & Answers

Numerical Labeling using sed

Hi, I have been working on this problem, but could only get so far. I have a file that looks like this (cat,chimp,(((dog,cat,cow),orangutan),((horse,((cat,dog),(cow,pig))),cat,mouse,rat))); I would like after each instance of the word 'cat' to have an incrementing numerical label. I... (5 Replies)
Discussion started by: cavanac2
5 Replies

5. Shell Programming and Scripting

COMM and Numerical Sorting

Hi, Hope someone can shed some light on this... I have two lists of numbers I am comparing using COMM. If the first list is empty, and I sort both lists like so: DIFF=`comm -3 <(echo "$EMPTY" | sort -n) <(echo "$NUMBERS" | sort -n)`I get the error: comm: file 2 is not in sorted order But... (2 Replies)
Discussion started by: LostInTheWoods
2 Replies

6. Shell Programming and Scripting

variable numerical test

Hi I have a variable which should be any number between 1 and 50. It could also be any string/empty string. I have a code written below. The point is when the variable contains string. I don't want the code below to error out. Instead fall in the else bucket. && dothis_1 || dothis_2 (1 Reply)
Discussion started by: tostay2003
1 Replies

7. UNIX for Dummies Questions & Answers

Can grep do numerical comparisons?

Say for example I have a list of numbers.. 5 10 13 48 1 could I use grep to show only those numbers that are above 10? For various reasons I can only use grep... not awk or sed etc. (7 Replies)
Discussion started by: Uss_Defiant
7 Replies

8. UNIX for Dummies Questions & Answers

how to get the value of a numerical expression

Hi, All, I want to calculate a specific value of a Gaussian distribution, say the mean is a=3, variance is b=5, the indepentent variable is x=2, how could I get the y which is the Gaussian distribution value of x. Thanks, Jenny (1 Reply)
Discussion started by: Jenny.palmy
1 Replies

9. Shell Programming and Scripting

ksh numerical RegX

I need to distinguish between numerical characters in a script: echo "Enter a number." read num if (( $num = * )) ; then exit 0 fi this RegX does not work. Any suggestions? (5 Replies)
Discussion started by: prkfriryce
5 Replies

10. Shell Programming and Scripting

Numerical Decision

I'm tryning to do something like this, I have this file: spaces12tabgoodbye spaces3tabhello I want to copy to another file the lines that have the number above 10... I thought using sort -rn but I don't know how to discard the lines that have the number below 10. Any idea? Thanks (3 Replies)
Discussion started by: pmpx
3 Replies
Login or Register to Ask a Question
Attribute::Params::Validate(3)				User Contributed Perl Documentation			    Attribute::Params::Validate(3)

NAME
Attribute::Params::Validate - Define validation through subroutine attributes VERSION
version 1.08 SYNOPSIS
use Attribute::Params::Validate qw(:all); # takes named params (hash or hashref) # foo is mandatory, bar is optional sub foo : Validate( foo => 1, bar => 0 ) { ... } # takes positional params # first two are mandatory, third is optional sub bar : ValidatePos( 1, 1, 0 ) { ... } # for some reason Perl insists that the entire attribute be on one line sub foo2 : Validate( foo => { type => ARRAYREF }, bar => { can => [ 'print', 'flush', 'frobnicate' ] }, baz => { type => SCALAR, callbacks => { 'numbers only' => sub { shift() =~ /^d+$/ }, 'less than 90' => sub { shift() < 90 } } } ) { ... } # note that this is marked as a method. This is very important! sub baz : Validate( foo => { type => ARRAYREF }, bar => { isa => 'Frobnicator' } ) method { ... } DESCRIPTION
The Attribute::Params::Validate module allows you to validate method or function call parameters just like Params::Validate does. However, this module allows you to specify your validation spec as an attribute, rather than by calling the "validate" routine. Please see Params::Validate for more information on how you can specify what validation is performed. EXPORT This module exports everything that Params::Validate does except for the "validate" and "validate_pos" subroutines. ATTRIBUTES o Validate This attribute corresponds to the "validate" subroutine in Params::Validate. o ValidatePos This attribute corresponds to the "validate_pos" subroutine in Params::Validate. OO If you are using this module to mark methods for validation, as opposed to subroutines, it is crucial that you mark these methods with the ":method" attribute, as well as the "Validate" or "ValidatePos" attribute. If you do not do this, then the object or class used in the method call will be passed to the validation routines, which is probably not what you want. CAVEATS You must put all the arguments to the "Validate" or "ValidatePos" attribute on a single line, or Perl will complain. SEE ALSO
Params::Validate AUTHOR
Dave Rolsky, <autarch@urth.org> and Ilya Martynov <ilya@martynov.org> COPYRIGHT AND LICENSE
This software is Copyright (c) 2013 by Dave Rolsky and Ilya Martynov. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) perl v5.18.2 2017-10-06 Attribute::Params::Validate(3)