How to check a column contain numeric or char data type ??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check a column contain numeric or char data type ??
# 8  
Old 10-05-2006
awk -F"|" ' $1 ~ "^[0-9][0-9]*$" { print $1 }' file

this line work fine for all the test value like
23232@@
ww232323
2322%.%
3434*
-----
but why 4343$$44 is showing as numeric value ???
also 343$34
show as numeric and showing 3434

This expression is working for all other but not when the value contain $
can any one help ??

also i tried with echo $var | sed -n '/^[0-9][0-9]*$/p' same thing happened
any thing consist of 0-9 should be considered as numeric , this sed expression working fine except for the value 445$$343 or 23$899 some thing like this which contain $ , it is considering that as numeric .

Last edited by jambesh; 10-05-2006 at 09:59 AM..
# 9  
Old 10-05-2006
Quote:
Originally Posted by jambesh
Anbu,

Thanks a lot for being with me and helping me.
can you please tell me why we ned twice

getline var < "constraintfile"
getline var < "constraintfile"

??
Also for sample purpose i have given 4 column now but in actual we can have max 150 column.
how to deal if the number column is more then 30 .
I have taken the following
Quote:
col1|col2|col3|col4
Nu|char|char|Nu
as constraint file. We need the second line right
# 10  
Old 10-05-2006
Quote:
Originally Posted by jambesh
awk -F"|" ' $1 ~ "^[0-9][0-9]*$" { print $1 }' file

this line work fine for all the test value like
23232@@
ww232323
2322%.%
3434*
-----
but why 4343$$44 is showing as numeric value ???
also 343$34
show as numeric and showing 3434

This expression is working for all other but not when the value contain $
can any one help ??

also i tried with echo $var | sed -n '/^[0-9][0-9]*$/p' same thing happened
any thing consist of 0-9 should be considered as numeric , this sed expression working fine except for the value 445$$343 or 23$899 some thing like this which contain $ , it is considering that as numeric .
It should work fine. Its working fine for me. I dont know whats happening in your case
# 11  
Old 10-05-2006
Quote:
Also for sample purpose i have given 4 column now but in actual we can have max 150 column.
how to deal if the number column is more then 30 .
try this

Code:
awk -F"|" ' 
BEGIN {
getline var < "constraintfile"
getline var < "constraintfile"
n = split( var , arr , "|" )
for ( i = 1 ; i <= n ; ++i )
{
        if( arr[i] == "Nu" )
                regexp[i] = "^[0-9][0-9]*$"
        if( arr[i] == "char" )
                regexp[i] = "^[a-zA-Z][a-zA-Z]*$"
print regexp[i]
}
}
#$1 ~ regexp[1] && $2 ~ regexp[2] && $3 ~ regexp[3] && $4 ~ regexp[4] {
#print $0
{
for( i = 1 ; i <= NF ; ++i )
{
        if ( ! match ( $i , regexp[i] ) )
                break;
        if ( i == NF )
                print $0
}
}' file


Last edited by anbu23; 10-06-2006 at 11:33 AM..
# 12  
Old 10-06-2006
"^[0-9][0-9]*$" with regular expression to check for numeric is failed as it is accepting 4545$22 as numeric aslo 34343&232 is also as numeric
i want to accept 343.343 as numeric and 343343 as numeric other then that are non numeric.
I mean only decimal place and pure numeric form are considerd as numeric .
any special char inside is non numeric
# 13  
Old 10-06-2006
Quote:
Originally Posted by jambesh
"^[0-9][0-9]*$" with regular expression to check for numeric is failed as it is accepting 4545$22 as numeric aslo 34343&232 is also as numeric
i want to accept 343.343 as numeric and 343343 as numeric other then that are non numeric.
I mean only decimal place and pure numeric form are considerd as numeric .
any special char inside is non numeric
To accept 343.343 as numeric use this

"^[0-9.][0-9.]*$"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to add a numeric & special char to end of the first line

Need to add a numeric & special char to end of the first line Existing file: 12-11-16|11 2016 Jan 12:34:55|03:55| 13-10-16|10 2016 Jan 12:34:55|03:55|12-11-16|11 2016 Jan 12:34:55|03:55| 14-10-16|19 2016 Jan 12:34:55|03:55|13-11-16|11 2016 Jan 12:34:55|04:55| 15-10-16|18 2016 Jan... (11 Replies)
Discussion started by: Joselouis
11 Replies

2. Shell Programming and Scripting

Parsing of Char and Numeric in a file

Hi All, i'm working on some report and currently have this plain text file generated. server_name1|sdfd1deal | 1048572| 1040952| 99| 207| 1| 1 server_name1|dba1dbs | 83886048| 40730796| 48| 5762| 22764| 8... (4 Replies)
Discussion started by: fedora132010
4 Replies

3. Shell Programming and Scripting

check if a string is numeric

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

4. Shell Programming and Scripting

How to check for a Numeric Value?

Using shell, I have a variable, how can I check that variable for a numeric value such as "41.0"? My program needs to do one things if the numeric value is found, and another if something else such as a string of letter is found. is there a specific character that denotes a numeral? The... (2 Replies)
Discussion started by: chagan02
2 Replies

5. UNIX for Advanced & Expert Users

Check EOF char in Unix. OR To check file has been received completely from a remote system

Advance Thanks. (1) I would like to know any unix/Linux command to check EOF char in a file. (2) Or Any way I can check a file has been reached completely at machine B from machine A. Note that machine A ftp/scp the file to machine B at unknown time. (5 Replies)
Discussion started by: alexalex1
5 Replies

6. Shell Programming and Scripting

How to check if a column is having a numeric value or not in a file?

Hi, I want to know, how we find out if a column is having a numeric value or not. For Example if we have a csv file as ASDF,QWER,GHJK,123,FGHY,9876 GHTY,NVHR,WOPI,623,HFBS,5386 we need to find out if the 4th and 6th column has muneric value or not. Thanks in advance Keerthan (9 Replies)
Discussion started by: keerthan
9 Replies

7. Emergency UNIX and Linux Support

AWK - check column data

Hi, I have a data in a file . Infile: 1 e 1.2 1.6 5 f 2.3 3.6 3 g 1.2 2.6 6 i 2.3 3.6 8 o 1.2 3.6 output: 1 e 1.2 1.6 5 f 2.3 3.6 3 g 1.1 2.6 6 i 2.2 3.5 8 o 1.0 3.4 (17 Replies)
Discussion started by: vasanth.vadalur
17 Replies

8. Shell Programming and Scripting

Converting Char to Numeric

HI, Here I have the following output and want to do some mathematical calculation on C2 & C3 column. c1 c2 c3 c4 c5 l1 1-oct 12:30:01 12:35 abc xyz l2 1-oct 14:20:01 14:35 def ... (5 Replies)
Discussion started by: dear_abhi2007
5 Replies

9. Programming

check the given string is numeric or not.

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

10. Shell Programming and Scripting

how to check the file data type(ascii or binary)

hi i am receiving a file from one system , i have to verify the format of the file data i.e whether the data is in acii format or binary format, please help thanks in advance satya (1 Reply)
Discussion started by: Satyak
1 Replies
Login or Register to Ask a Question