Awk type checking


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk type checking
# 1  
Old 04-13-2007
Awk type checking

Hello,

How to check if two variables( fields in awk) have the same datatype ( INTEGER , REAL, TEXT ) ?
# 2  
Old 04-13-2007
Awk has no typing.
# 3  
Old 04-13-2007
Code:
$ cat file
12
23.34
asasa
12
23.23
23.34
a.asa
12asa
$ awk ' $1 ~ /^[0-9]+$/ { print $1" no" ; next }
> $1 ~ /^[0-9]+.[0-9]+$/ { print $1" real"; next }
> { print $1" alpha" } ' file
12 no
23.34 real
asasa alpha
12 no
23.23 real
23.34 real
a.asa alpha
12asa alpha

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Count occurrence of string (based on type) in a column using awk

Hello, I have a table that looks like what is shown below: AA BB CC XY PQ RS AA BB CC XY RS I would like the total counts depending on the set they belong to: if search pattern is in {AA, BB, CC} --> count them as Type1 | wc -l (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

2. Shell Programming and Scripting

awk - checking last three characters

Hello, I am working with some very large files (upwards of 1M records). I have written code to parse out a lot of the data and am using awk rather than a built-in "while read LINE" for performance (I have tested both ways). That said, I now need to read each of these incoming lines, check the ninth... (2 Replies)
Discussion started by: dagamier
2 Replies

3. UNIX for Advanced & Expert Users

Checking OS Type on Servers

is there a way to do this through snmp? i'm writing a shell script that will be run against several servers, but when i run the script, the most i get back from snmp is information that is simple. the snmp in the script tells me if the box is linux or solaris. but it doesn't tell me the... (7 Replies)
Discussion started by: SkySmart
7 Replies

4. Shell Programming and Scripting

Checking conditions with AWK

Input File1 0BB2 2A11 Split,FriApr80625,1507_7RAID5 0BF6 2829 Synchronized,FriJan140653,1507_7RAID5 0BF6 282A Split,FriApr80625,1507_7RAID5 0C7C 199E Synchronized,FriJan140653,1507_7RAID5 0C7C 1BCC Split,FriApr80625,1507_7RAID5 0DCA 0A9B ... (12 Replies)
Discussion started by: greycells
12 Replies

5. Shell Programming and Scripting

Awk and checking options

My task is that when the user calls the script 1. If user calls script with awk -v dtmax= -v stdlim= -f ../Scripts/add-rgauss-xt.awk fin.xt > fout.xt rgauss will return mean + (stdlim * sigma) 2. If user calls script with awk -v dtmax= -f ../Scripts/add-rgauss-xt.awk fin.xt > fout.xt... (4 Replies)
Discussion started by: kristinu
4 Replies

6. Shell Programming and Scripting

awk if percent % checking

hi everyone, # cat a a 10% b 25.5% c 91% d 50% # cat a | awk '$2 >= 90%; END {print $_}' awk: $2 > 90%; END {print $_} awk: ^ syntax error awk: each rule must have a pattern or an action part how to do only print when 2nd coln >= 90%. Thanks (6 Replies)
Discussion started by: jimmy_y
6 Replies

7. Shell Programming and Scripting

awk/grep type question

Hi there, I have a Solaris machine with an ifconfig output similar to below lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 inet 127.0.0.1 netmask ff000000 e1000g0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2 inet... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

8. Shell Programming and Scripting

Problem with type-casting in awk

Hi I'm trying to write a script which takes an integer as input and checks for files with size > input and displays it on screen. The code I've tried : echo 'Enter the min file size expected' read filesize du -ah <folder name> | awk -F: '$1>int(filesize) {print $1,$2)' is always... (28 Replies)
Discussion started by: vivek.bharadwaj
28 Replies

9. Shell Programming and Scripting

Perl data type checking

I am using perl 5.8.0. I need to check some values to see it they are floats. Our system does not have Data::Types so I can't use is_float. Is there something else that I can use? The only thing in Data is Dump.pm. I am not allowed to download anything to our system so I have to use what I have.... (3 Replies)
Discussion started by: ajgwin
3 Replies
Login or Register to Ask a Question