Sponsored Content
Full Discussion: Check if the value is Number
Top Forums Shell Programming and Scripting Check if the value is Number Post 302435761 by ashwin3086 on Thursday 8th of July 2010 07:10:42 AM
Old 07-08-2010
Check if the value is Number

Hi,

I have a file with data as given
Code:
$cat file1.txt
123
234
23e
234.456
234.876e
345.00

I am checking if the values are proper integers using the command.
Code:
 nawk -F'|' 'int($1)!=$1 {printf "Error in field 1|"$0"\n"}' file1.txt

This is checking for only integers ( without precision ).I want to check for Number as well (with precision) But even if it is with precision it is valid number. How can i do that??

But these as given below should be detected as invalid and rest all as valid.

23e
234.876e

Last edited by ashwin3086; 07-08-2010 at 08:11 AM.. Reason: number added
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Check if variable is a number

If I have a variable $X, how do I check it is a number? Many thanks. (2 Replies)
Discussion started by: handak9
2 Replies

2. Shell Programming and Scripting

How to check whether a string is number or not

Hi , I am facing a problem .. which looks simple... but took 2 days of mine.. even now it is not solved completely.. I have one variable..., want to know whether that variable contains number... canbe +ve or -ve ... Values +35 --- number -43 --- number 45A -- non number... (12 Replies)
Discussion started by: shihabvk
12 Replies

3. Shell Programming and Scripting

number check in perl

Hi,, this is returning true in all cases..( other than 10 dig number also) what could be wrong?? (2 Replies)
Discussion started by: shellwell
2 Replies

4. Shell Programming and Scripting

check number of character

hi, I would like to calculate number of character for a number, for exemple : 1200 --> there are 4 characters , 120001 -> 5 characters (4 Replies)
Discussion started by: francis_tom
4 Replies

5. Shell Programming and Scripting

To check a word is number or not

Hi, I have one file like 00123. And this file name is generated as a sequence. So how can I confirm the generated file name is a number, not a special character or alphabets. Can anybody help me out. Thanks in advance. (3 Replies)
Discussion started by: Kattoor
3 Replies

6. Shell Programming and Scripting

TCSH Check if number is even

Hey, I am trying to check if an integer is even in a tcsh script This is what I am running now set lattest = ` echo $latmin "%2" | bc -l ` echo $lattest if ( $lattest == 0 ) then echo "min is already even" else if ( $lattest =! 0 ) then set latmin = ` echo $latmin "+1" |... (2 Replies)
Discussion started by: travish12
2 Replies

7. Shell Programming and Scripting

Check params for number

I have 2 and three params, both I should make sure thay numbers at one single line insted of checking for each one . Example I wroote the following way.. checking for 2 and three seperately but I shud be able to do it at on statement echo $2 | egrep '^+$' >/dev/null 2>&1 if ; then echo... (2 Replies)
Discussion started by: raopatwari
2 Replies

8. Shell Programming and Scripting

number of instance check

Hi, We are getting a curios result in one of AIX script. Its executed using !/bin/ksh . After following line we get result of 3 in in the variable instance_count. instance_count=`ps -ef | grep "script_check_instances.sh" | grep -v "grep" | wc -l` But once we do a "ps -aef | grep... (2 Replies)
Discussion started by: niba
2 Replies

9. Shell Programming and Scripting

How to check number of group of file.?

Hi Gurus, I need check existing number of file based on the list in file list. for example: in my file list. I have below: abc, file1.txt abc, file2.txt abc, file3.txt abc, file4.txt cde, filea1.txt cde, filea2.txt cde, filea3.txt ... in my current file direcotry, I have file:... (0 Replies)
Discussion started by: ken6503
0 Replies

10. UNIX for Dummies Questions & Answers

How to check if a number exists?

Hello, May i please know how do i check if the given input argument is one of the listed numbers then success else failure. I am using bash shell. if then echo "success" else echo "failure" fi Thank you. (2 Replies)
Discussion started by: Ariean
2 Replies
STRFMON(3)						     Linux Programmer's Manual							STRFMON(3)

NAME
strfmon - convert monetary value to a string SYNOPSIS
#include <monetary.h> ssize_t strfmon(char *s, size_t max, const char *format, ...); DESCRIPTION
The strfmon() function formats the specified amounts according to the format specification format and places the result in the character array s of size max. Ordinary characters in format are copied to s without conversion. Conversion specifiers are introduced by a `%' character. Immediately following it there can be zero or more of the following flags: =f The single-byte character f is used as the numeric fill character (to be used with a left precision, see below). When not speci- fied, the space character is used. ^ Do not use any grouping characters that might be defined for the current locale. By default, grouping is enabled. ( or + The ( flag indicates that negative amounts should be enclosed between parentheses. The + flag indicates that signs should be handled in the default way, that is, amounts are preceded by the locale's sign indication, e.g., nothing for positive, "-" for negative. ! Omit the currency symbol. - Left justify all fields. The default is right justification. Next, there may be a field width: a decimal digit string specifying a minimum field width in bytes. The default is 0. A result smaller than this width is padded with spaces (on the left, unless the left-justify flag was given). Next, there may be a left precision of the form "#" followed by a decimal digit string. If the number of digits left of the radix character is smaller than this, the representation is padded on the left with the numeric fill character. Grouping characters are not counted in this field width. Next, there may be a right precision of the form "." followed by a decimal digit string. The amount being formatted is rounded to the spec- ified number of digits prior to formatting. The default is specified in the frac_digits and int_frac_digits items of the current locale. If the right precision is 0, no radix character is printed. (The radix character here is determined by LC_MONETARY, and may differ from that specified by LC_NUMERIC.) Finally, the conversion specification must be ended with a conversion character. The three conversion characters are % (In this case the entire specification must be exactly "%%".) Put a `%' character in the result string. i One argument of type double is converted using the locale's international currency format. n One argument of type double is converted using the locale's national currency format. RETURN VALUE
The strfmon() function returns the number of characters placed in the array s, not including the terminating NUL character, provided the string, including the terminating NUL, fits. Otherwise, it sets errno to E2BIG, returns -1, and the contents of the array is undefined. EXAMPLE
The call strfmon(buf, sizeof(buf), "[%^=*#6n] [%=*#6i]", 1234.567, 1234.567); outputs [ fl **1234,57] [ NLG **1 234,57] in the Dutch locale (with fl for "florijnen" and NLG for Netherlands Guilders). The grouping character is very ugly because it takes as much space as a digit, while it should not take more than half that, and will no doubt cause confusion. Surprisingly, the "fl" is preceded and followed by a space, and "NLG" is preceded by one and followed by two spaces. This may be a bug in the locale files. The Italian, Aus- tralian, Swiss and Portuguese locales yield [ L. **1235] [ ITL **1.235] [ $**1234.57] [ AUD **1,234.57] [Fr. **1234,57] [CHF **1.234,57] [ **1234$57Esc] [ **1.234$57PTE ] SEE ALSO
setlocale(3), sprintf(3), locale(7) Linux 2000-12-05 STRFMON(3)
All times are GMT -4. The time now is 04:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy