Pattern to match decimal number and interger


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pattern to match decimal number and interger
# 1  
Old 06-27-2011
Error Pattern to match decimal number and interger

Hi,

i've a code
Code:
if (($A && ((!($A =~ /^\d+$/)))))
{
 -- -- not a number
}
else
{
--- its number.
}

which matches for integer value, i need to modify that pattern where it matches decimal number with 2 decimal points and also integer value.
for eg: values 10, 10.00. 0.1, 1 , 3 must print successful . and numbers like
10.0000 0.0001, 01.111 and alphabets 11.ssasd should not accept.

Thanks,
asak
# 2  
Old 06-27-2011
Hi,

Try regexp in this script:
Code:
use warnings;
use strict;

while ( <DATA> ) {
    chomp;
    printf "%s\n", $_ if /^\d+(?:\.\d{1,2})?$/;
}

__DATA__
10
10.0000
10.00
0.00001
0.1
1
01.111
3
11.ssasd

Regards,
Birei
This User Gave Thanks to birei For This Post:
# 3  
Old 06-27-2011
MySQL

hi Birei,

Thanks a lot.

Regards,
asak

---------- Post updated at 05:57 AM ---------- Previous update was at 05:56 AM ----------

hi,

Found this regx also

if (($A && ((!($A =~ /^\d+(\.\d{1,2})?$/)))))


which works for 2 decimal numbers and inegers.

Thanks,
Asak
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Egrep patterns in a file and limit number of matches to print for each pattern match

Hi I need to egrep patterns in a file and limit number of matches to print for each matched pattern. -m10 option is not working out in my sun solaris 5.10 Please guide me the options to achieve. if i do head -10 , i wont be getting all pattern match results as output since for a... (10 Replies)
Discussion started by: ananan
10 Replies

2. Shell Programming and Scripting

awk if condition match and fix print decimal place

Hi All, I have problem in the middle of implementing to users, whereby the complaint is all about the decimal place which is too long. I need two decimal places only, but the outcome from command is always fixed to 6. See the sample : before: Sort Total Site Sort SortName Parts ... (3 Replies)
Discussion started by: horsepower
3 Replies

3. Shell Programming and Scripting

Rearrange or replace only the second line after pattern match or pattern match

Im using the command below , but thats not the output that i want. it only prints the odd and even numbers. awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}' Im hoping for something like this file1: Text hi this is just a test text1 text2 text3 text4 text5 text6 Text hi... (2 Replies)
Discussion started by: invinzin21
2 Replies

4. Shell Programming and Scripting

Match pattern and print the line number of occurence using awk

Hi, I have a simple problem but i guess stupid enough to figure it out. i have thousands rows of data. and i need to find match patterns of two columns and print the number of rows. for example: inputfile abd abp 123 abc abc 325 ndc ndc 451 mjk lkj... (3 Replies)
Discussion started by: redse171
3 Replies

5. Shell Programming and Scripting

Finding log files that match number pattern

I have logs files which are generated each day depending on how many processes are running. Some days it could spin up 30 processes. Other days it could spin up 50. The log files all have the same pattern with the number being the different factor. e.g. LOG_FILE_1.log LOG_FILE_2.log etc etc ... (2 Replies)
Discussion started by: atelford
2 Replies

6. UNIX for Dummies Questions & Answers

Match Pattern after certain pattern and Print words next to Pattern

Hi experts , im new to Unix,AWK ,and im just not able to get this right. I need to match for some patterns if it matches I need to print the next few words to it.. I have only three such conditions to match… But I need to print only those words that comes after satisfying the first condition..... (2 Replies)
Discussion started by: 100bees
2 Replies

7. Shell Programming and Scripting

grep - match files containing minimum number of pattern matches

I want to search a bunch of files and list only those containing a minimum number of pattern matches. So if I want to identify files containing 3 (or more) instances of the pattern "said:" and I have file1 that contains the lines: He said: She said: and file2 that contains the lines: He... (3 Replies)
Discussion started by: stumpyuk
3 Replies

8. Shell Programming and Scripting

Match first pattern first then extract second pattern match

My input file: <accession>Q91G55</accession> <name>043L_IIV6</name> <protein> <recommendedName> <location> <position position="294"/> </location> <fullName>Uncharacterized protein 043L</fullName> <accession>P18556</accession> <name>1106L_ASFB7</name> <protein> <recommendedName>... (5 Replies)
Discussion started by: patrick87
5 Replies

9. Shell Programming and Scripting

Extracting N lines match number X of a pattern

Hi All, as the title says I need to extract N lines after match number X of a pattern. e.g. 111 xxx xxx 111 yyy yyy 111 www www 111 zzz zzz I would like to extract the two lines after the second 111 occurrence. I tried with grep but I didn't find any options to do that. Any... (11 Replies)
Discussion started by: f_o_555
11 Replies
Login or Register to Ask a Question