10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello,
I have a file of strings a below:-
4358RYFHD9845
28/COC/UYF984
9834URD 98HJDU
I need to extract all the first numeric character of every sting as follows:-
4358
28
9834
thanks to suggest ASAP
Regards,
Jasi
Use code tags, thanks. (7 Replies)
Discussion started by: jassi10781
7 Replies
2. Programming
I have a string
opt="row234"
I want to put "row" in a string and 234 in an int.
In general it should be
opt="textnum"
I want to store text in a string and num in an int. (6 Replies)
Discussion started by: kristinu
6 Replies
3. UNIX for Dummies Questions & Answers
Hi All,
I am trying to to compare a string variable with a string literal inside a loop but keep getting the
./testifstructure.sh: line 6:
#!/bin/sh
BOOK_LIST="BOOK1 BOOK2"
for BOOK in ${BOOK_LIST}
do
if
then echo '1'
else
echo '2'
fi
done
Please use next... (1 Reply)
Discussion started by: daveu7
1 Replies
4. Shell Programming and Scripting
I checked all the previous threads related to this and tried this.
My input is all numbers or decimals greater than zero everytime.
I want to check the same in the korn shell script.
Just validate the string to be numeric.
This is what I am doing.
var="12345"
if ) -o "$var" !=... (14 Replies)
Discussion started by: megha2525
14 Replies
5. Shell Programming and Scripting
Hi Champs,
I am a newbie to unix world, and I am trying to built a script which seems to be far tough to be done alone by me.....
" I am having a raw csv file which contains around 50 fields..."
From that file I have to grep 2 fields "A" and "B"....field "A" is to be aligned vertically... (11 Replies)
Discussion started by: jitendra.pat04
11 Replies
6. Shell Programming and Scripting
Hi frnds
Im facing an issues while trying to compare string using IF stmt, my code is:
chkMsgName=`Service Fee Detail`
if
then
if
then
if
then
echo "Valid File Ready for processing"
fi
fi
... (5 Replies)
Discussion started by: balesh
5 Replies
7. Shell Programming and Scripting
I have a file whose contents are:
$ cat file1
cfd_V03R37
cfd_V03R38
tried
sed 's///g' file1 > file2
$cat file1
0337
0338
Is there any way by which i can work on same file and write o/p to the same file instead of using file2 (3 Replies)
Discussion started by: vjasai
3 Replies
8. Programming
Hi,
how to check the given string is numeric or not , without converting ( using strtol...).
for ex: if string is C01 - non-numeric data
if string is 001 - numeric data
TIA (11 Replies)
Discussion started by: knowledge_gain
11 Replies
9. Shell Programming and Scripting
given a string passed to a program that supposed to be numeric and of a certain length say 8 digits - so say for e.g. need to verify this 01234567
How would I parse this string to validat it meet requirements
I tried to use * | sed /\(\{8})/
Thanks in advance (1 Reply)
Discussion started by: dragrid
1 Replies
10. Shell Programming and Scripting
Hi,
I have read some figures from a text file by getting the position and wish to do some checking, but it seem like it won't work.
eg. my figure is 0.68 it still go the the else statement,
it seems like it treat it as a text instead of number.
Anybody can Help ? Thanks.
# only... (3 Replies)
Discussion started by: kflee2000
3 Replies
Scalar::Number(3pm) User Contributed Perl Documentation Scalar::Number(3pm)
NAME
Scalar::Number - numeric aspects of scalars
SYNOPSIS
use Scalar::Number qw(scalar_num_part);
$num = scalar_num_part($scalar);
use Scalar::Number qw(sclnum_is_natint sclnum_is_float);
if(sclnum_is_natint($value)) { ...
if(sclnum_is_float($value)) { ...
use Scalar::Number qw(sclnum_val_cmp sclnum_id_cmp);
@sorted_nums = sort { sclnum_val_cmp($a, $b) } @floats;
@sorted_nums = sort { sclnum_id_cmp($a, $b) } @floats;
DESCRIPTION
This module is about the numeric part of plain (string) Perl scalars. A scalar has a numeric value, which may be expressed in either the
native integer type or the native floating point type. Many values are expressible both ways, in which case the exact representation is
insignificant. To fully understand Perl arithmetic it is necessary to know about both of these representations, and the differing
behaviours of numbers according to which way they are expressible.
This module provides functions to extract the numeric part of a scalar, classify a number by expressibility, and compare numbers across
representations.
This module is implemented in XS, with a pure Perl backup version for systems that can't handle XS.
FUNCTIONS
Each "sclnum_" function takes one or more scalar numeric arguments to operate on. These arguments must be numeric; giving non-numeric
arguments will cause mayhem. See "is_number" in Params::Classify for a way to check for numericness. Only the numeric value of the scalar
is used; the string value is completely ignored, so dualvars are not a problem.
Decomposition
scalar_num_part(SCALAR)
Extracts the numeric value of SCALAR, and returns it as a pure numeric scalar. The argument is permitted to be any scalar.
Every scalar has both a string value and a numeric value. In pure string scalars, those resulting from string literals or string
operations, the numeric value is determined from the string value. In pure numeric scalars, those resulting from numeric literals or
numeric operations, the string value is determined from the numeric value. In the general case, however, a plain scalar's string and
numeric values may be set independently, which is known as a dualvar. Non-plain scalars, principally references, determine their
string and numeric values in other ways, and in particular a reference to a blessed object can stringify and numerify however the class
wishes.
This function does not warn if given an ostensibly non-numeric argument, because the whole point of it is to extract the numeric value
of scalars that are not pure numeric.
Classification
sclnum_is_natint(VALUE)
Returns a truth value indicating whether the provided VALUE can be represented in the native integer data type. If the floating point
type includes signed zeroes then they do not qualify; the only zero representable in the integer type is unsigned.
sclnum_is_float(VALUE)
Returns a truth value indicating whether the provided VALUE can be represented in the native floating point data type. If the floating
point type includes signed zeroes then an unsigned zero (from the native integer type) does not qualify.
Comparison
sclnum_val_cmp(A, B)
Numerically compares the values A and B. Integer and floating point values are compared correctly with each other, even if there is no
available format in which both values can be accurately represented. Returns -1, 0, +1, or undef, indicating whether A is less than,
equal to, greater than, or not comparable with B. The "not comparable" situation arises if either value is a floating point NaN (not-
a-number). All flavours of zero compare equal.
This is very similar to Perl's built-in <=> operator. The only difference is the capability to compare integer against floating point
(where neither can be represented exactly in the other's format). <=> performs such comparisons in floating point, losing accuracy of
the integer value.
sclnum_id_cmp(A, B)
This is a comparison function supplying a total ordering of scalar numeric values. Returns -1, 0, or +1, indicating whether A is to be
sorted before, the same as, or after B.
The ordering is of the identities of numeric values, not their numerical values. If floating point zeroes are signed, then the three
types (positive, negative, and unsigned) are considered to be distinct. NaNs compare equal to each other, but different from all
numeric values. The exact ordering provided is mostly numerical order: NaNs come first, followed by negative infinity, then negative
finite values, then negative zero, then unsigned zero, then positive zero, then positive finite values, then positive infinity.
In addition to sorting, this function can be useful to check for a zero of a particular sign.
BUGS
In Perl 5.6, if configured with a wider-than-usual native integer type such that there are native integers that can't be represented
exactly in the native floating point type, it is not always possible to distinguish between integer and floating point values in pure Perl
code. In order to get the full benefit of either type, one is expected (by the numeric semantics) to know in advance which of them one is
using. The pure Perl version of this module can't operate on such a system, but the XS version works fine. This problem is resolved by
Perl 5.8's new numeric semantics.
SEE ALSO
Data::Float, Data::Integer, perlnumber(1)
AUTHOR
Andrew Main (Zefram) <zefram@fysh.org>
COPYRIGHT
Copyright (C) 2007, 2009, 2010 Andrew Main (Zefram) <zefram@fysh.org>
LICENSE
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl v5.14.2 2011-11-15 Scalar::Number(3pm)