Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Decimal numbers and letters in the same collums: round numbers Post 302988540 by bakunin on Tuesday 27th of December 2016 05:13:59 PM
Old 12-27-2016
Quote:
Originally Posted by RudiC
if the field in question contains ANY non-numeric character, use "%s" else use "%f" with an adaptable width.
Darn, you are right. I hate it when you do that to me. ;-)

The regexp can be repaired perhaps: (var ~ /^-*[0-9.]*[0-9]+$/).

Testing for [[:alpha:]] alone will also not do the trick because of "misformed" numbers like: "123.456.789", which should not be treated as numbers despite passing the [[:digit:]]-test. Thinking about it it is not possible to determine "number or not" based on characters alone:

Code:
-123.456  # is a number
123-456.  # is not


I hope this helps.

bakunin

Last edited by bakunin; 12-27-2016 at 06:19 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Letters, Numbers or Alphanumerical

How do I check if a variable consisted of letters, numbers or both letters and numbers? For example, I have a variable $X and I want to print "1" if it contains only letters, "2" if it contains only numbers and "3" if it contains both (2 Replies)
Discussion started by: sleepster
2 Replies

2. UNIX for Dummies Questions & Answers

Help! scrolling numbers and letters

Hello all I am a unix newbie.... I have a sun netra t1 and it is freaking out I am connected to it through a console port, and it is just spitting out a ton on numbers and letters like below its just keeps going and going. I have tried rebooting it and I cannot get it back to any kind of a... (1 Reply)
Discussion started by: intraining11
1 Replies

3. Shell Programming and Scripting

decimal numbers

Hi friends How can I use "for loop" for decimal numbers? ex: 0.1 < x < 0.6 I used this commands but does'nt work. LIMIT=0.6 for ((x=0.1; x<=LIMIT; x++)) do - - - done Many thanks (1 Reply)
Discussion started by: snow
1 Replies

4. Shell Programming and Scripting

Regarding decimal numbers

Hello... I am new to unix and I am wondering if in a C-shell script , Are we supposed to use only whole numbers........ for example..if a program needs to calculate the average of some numbers........ @ avg = (($1 +$2 + $3)/3)) is returning a whole number.........How can a decimal be... (7 Replies)
Discussion started by: ravindra22
7 Replies

5. Shell Programming and Scripting

sed command, look for numbers following letters

If I have a set of strings, C21 F231 H42 1C10 1F113 and I want to isolate the ints following the char, what would the sed string be to find numbers after letters? If I do, *, I will get numbers after letters, but I am looking to do something like, sed 's/*/\t*/g' this will give me... (14 Replies)
Discussion started by: LMHmedchem
14 Replies

6. Shell Programming and Scripting

reducing values in columns with both numbers and letters

Hi, I columns with both number and letters however i need the number 4 trimmed off the lines that have 3 numbers in them so it just because the 2 preceding numbers only For example V25QG2-K18QG-V25CG2 L26HG-L17HA-L26CG I434QD1-L19HB2-I434CD1 I434QD1-A31QB-I434CD1 ... (7 Replies)
Discussion started by: olifu02
7 Replies

7. Shell Programming and Scripting

awk : match only the pattern string , not letters or numbers after that.

Hi Experts, I am finding difficulty to get exact match: file OPERATING_SYSTEM=HP-UX LOOPBACK_ADDRESS=127.0.0.1 INTERFACE_NAME="lan3" IP_ADDRESS="10.53.52.241" SUBNET_MASK="255.255.255.192" BROADCAST_ADDRESS="" INTERFACE_STATE="" DHCP_ENABLE=0 INTERFACE_NAME="lan3:1"... (6 Replies)
Discussion started by: rveri
6 Replies

8. Shell Programming and Scripting

Sorting mixed numbers and letters

Hello, I have a file such as this: chr1 chr2 chr1 chr2 chr3 chr10 chr4 chr5 chrz chr1AI want to sort it, I use this command: sort -k1 -th -n testfilebut I get this output, how can I fix this? chr1 chr1 chr10 chr1A chr2 chr2 (3 Replies)
Discussion started by: Homa
3 Replies

9. UNIX for Dummies Questions & Answers

sed - extract a group of Letters/numbers

I have a file with hundreds of lines in it. I wanted to extract anything that matches the following: KR followed by 4 digits: example KR1201 cat list | sed "s///g" Is the closest I've come, and obviously it is not what I want. This would remove all of the items that I want and leave me... (2 Replies)
Discussion started by: newbie2010
2 Replies

10. Shell Programming and Scripting

[FUN] Numbers to Roman letters/num

Heyas Just a little fun script (code block) i'd like to share for fun. #/bin/bash # roman.sh # # Function # num2roman() { # NUM # Returns NUM in roman letters # input=$1 # input num output="" # Clear output string len=${#input} # Initial length to count down ... (9 Replies)
Discussion started by: sea
9 Replies
Regexp::Common::number(3)				User Contributed Perl Documentation				 Regexp::Common::number(3)

NAME
Regexp::Common::number -- provide regexes for numbers SYNOPSIS
use Regexp::Common qw /number/; while (<>) { /^$RE{num}{int}$/ and print "Integer "; /^$RE{num}{real}$/ and print "Real "; /^$RE{num}{real}{-base => 16}$/ and print "Hexadecimal real "; } DESCRIPTION
Please consult the manual of Regexp::Common for a general description of the works of this interface. Do not use this module directly, but load it via Regexp::Common. $RE{num}{int}{-base}{-sep}{-group}{-places} Returns a pattern that matches an integer. If "-base => B" is specified, the integer is in base B, with "2 <= B <= 36". For bases larger than 10, upper case letters are used. The default base is 10. If "-sep => P" is specified, the pattern P is required as a grouping marker within the number. If this option is not given, no grouping marker is used. If "-group => N" is specified, digits between grouping markers must be grouped in sequences of exactly N digits. The default value of N is 3. If "-group => N,M" is specified, digits between grouping markers must be grouped in sequences of at least N digits, and at most M digits. This option is ignored unless the "-sep" option is used. If "-places => N" is specified, the integer recognized must be exactly N digits wide. If "-places => N,M" is specified, the integer must be at least N wide, and at most M characters. There is no default, which means that integers are unlimited in size. This option is ignored if the "-sep" option is used. For example: $RE{num}{int} # match 1234567 $RE{num}{int}{-sep=>','} # match 1,234,567 $RE{num}{int}{-sep=>',?'} # match 1234567 or 1,234,567 $RE{num}{int}{-sep=>'.'}{-group=>4} # match 1.2345.6789 Under "-keep" (see Regexp::Common): $1 captures the entire number $2 captures the optional sign of the number $3 captures the complete set of digits $RE{num}{real}{-base}{-radix}{-places}{-sep}{-group}{-expon} Returns a pattern that matches a floating-point number. If "-base=N" is specified, the number is assumed to be in that base (with A..Z representing the digits for 11..36). By default, the base is 10. If "-radix=P" is specified, the pattern P is used as the radix point for the number (i.e. the "decimal point" in base 10). The default is "qr/[.]/". If "-places=N" is specified, the number is assumed to have exactly N places after the radix point. If "-places=M,N" is specified, the number is assumed to have between M and N places after the radix point. By default, the number of places is unrestricted. If "-sep=P" specified, the pattern P is required as a grouping marker within the pre-radix section of the number. By default, no separator is allowed. If "-group=N" is specified, digits between grouping separators must be grouped in sequences of exactly N characters. The default value of N is 3. If "-expon=P" is specified, the pattern P is used as the exponential marker. The default value of P is "qr/[Ee]/". For example: $RE{num}{real} # matches 123.456 or -0.1234567 $RE{num}{real}{-places=>2} # matches 123.45 or -0.12 $RE{num}{real}{-places=>'0,3'} # matches 123.456 or 0 or 9.8 $RE{num}{real}{-sep=>'[,.]?'} # matches 123,456 or 123.456 $RE{num}{real}{-base=>3'} # matches 121.102 Under "-keep": $1 captures the entire match $2 captures the optional sign of the number $3 captures the complete mantissa $4 captures the whole number portion of the mantissa $5 captures the radix point $6 captures the fractional portion of the mantissa $7 captures the optional exponent marker $8 captures the entire exponent value $9 captures the optional sign of the exponent $10 captures the digits of the exponent $RE{num}{dec}{-radix}{-places}{-sep}{-group}{-expon} A synonym for $RE{num}{real}{-base=>10}{...} $RE{num}{oct}{-radix}{-places}{-sep}{-group}{-expon} A synonym for $RE{num}{real}{-base=>8}{...} $RE{num}{bin}{-radix}{-places}{-sep}{-group}{-expon} A synonym for $RE{num}{real}{-base=>2}{...} $RE{num}{hex}{-radix}{-places}{-sep}{-group}{-expon} A synonym for $RE{num}{real}{-base=>16}{...} $RE{num}{decimal}{-base}{-radix}{-places}{-sep}{-group} The same as $RE{num}{real}, except that an exponent isn't allowed. Hence, this returns a pattern matching decimal numbers. If "-base=N" is specified, the number is assumed to be in that base (with A..Z representing the digits for 11..36). By default, the base is 10. If "-radix=P" is specified, the pattern P is used as the radix point for the number (i.e. the "decimal point" in base 10). The default is "qr/[.]/". If "-places=N" is specified, the number is assumed to have exactly N places after the radix point. If "-places=M,N" is specified, the number is assumed to have between M and N places after the radix point. By default, the number of places is unrestricted. If "-sep=P" specified, the pattern P is required as a grouping marker within the pre-radix section of the number. By default, no separator is allowed. If "-group=N" is specified, digits between grouping separators must be grouped in sequences of exactly N characters. The default value of N is 3. For example: $RE{num}{decimal} # matches 123.456 or -0.1234567 $RE{num}{decimal}{-places=>2} # matches 123.45 or -0.12 $RE{num}{decimal}{-places=>'0,3'} # matches 123.456 or 0 or 9.8 $RE{num}{decimal}{-sep=>'[,.]?'} # matches 123,456 or 123.456 $RE{num}{decimal}{-base=>3'} # matches 121.102 Under "-keep": $1 captures the entire match $2 captures the optional sign of the number $3 captures the complete mantissa $4 captures the whole number portion of the mantissa $5 captures the radix point $6 captures the fractional portion of the mantissa $RE{num}{square} Returns a pattern that matches a (decimal) square. Because Perl's arithmetic is lossy when using integers over about 53 bits, this pattern only recognizes numbers less than 9000000000000000, if one uses a Perl that is configured to use 64 bit integers. Otherwise, the limit is 2147483647. These restrictions were introduced in versions 2.116 and 2.117 of Regexp::Common. Regardless whether "-keep" was set, the matched number will be returned in $1. This pattern is available for version 5.008 and up. $RE{num}{roman} Returns a pattern that matches an integer written in Roman numbers. Case doesn't matter. Only the more modern style, that is, no more than three repetitions of a letter, is recognized. The largest number matched is MMMCMXCIX, or 3999. Larger numbers cannot be expressed using ASCII characters. A future version will be able to deal with the Unicode symbols to match larger Roman numbers. Under "-keep", the number will be captured in $1. SEE ALSO
Regexp::Common for a general description of how to use this interface. AUTHOR
Damian Conway (damian@conway.org) MAINTAINANCE
This package is maintained by Abigail (regexp-common@abigail.be). BUGS AND IRRITATIONS
Bound to be plenty. For a start, there are many common regexes missing. Send them in to regexp-common@abigail.be. LICENSE and COPYRIGHT This software is Copyright (c) 2001 - 2009, Damian Conway and Abigail. This module is free software, and maybe used under any of the following licenses: 1) The Perl Artistic License. See the file COPYRIGHT.AL. 2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2. 3) The BSD Licence. See the file COPYRIGHT.BSD. 4) The MIT Licence. See the file COPYRIGHT.MIT. perl v5.16.2 2011-04-16 Regexp::Common::number(3)
All times are GMT -4. The time now is 10:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy