Number comparision in AWK


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Number comparision in AWK
# 1  
Old 11-22-2006
Number comparision in AWK

Hi,

I have a file like this.

"
Code:
2006","10",25,"U","1129","32","C",0,0,0,0,0,0,0,0,0,0,0,0,352,16,4,0,0,0,0,0,"80",,1
"2006","11",25,"U","1148","32","C",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"80",,2
"2006","14",25,"U","1149","10","C",0,0,0,0,0,0,0,0,0,0,0,0,560,12,0,0,0,0,0,0,"80",,3
"2006","10",25,"U","1200","8","C",0,0,0,0,0,0,0,0,0,0,0,0,112,16,0,0,0,0,0,0,"80",,4
"2006","11",25,"U","1223","10","C",0,0,0,0,0,0,0,0,0,0,0,0,720,15,0,0,0,0,0,0,"80",,5
"2006","10",25,"U","1248","32","C",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"80",,6
"2006","0",25,"U","1253","35","C",40,0,0,0,40,0,0,0,0,0,0,0,33,0,0,0,0,0,0,0,"80",,7
"2006","9",25,"U","1256","35","C",292,0,0,0,292,0,0,0,0,0,0,0,52,0,0,0,0,0,0,0,"80",,8

I want to retrieve all the records from this file where the 2nd column is greater than 10. I want to achieve this using AWK. Is the comparision different for strings and numbers.

I tried the below command and it did not work out.

Code:
 awk -F, '{ if ($2>"10") print $0;}' File.csv

Any help is appreciated. Thanks

Kumar
# 2  
Old 11-22-2006
Code:
nawk -v q='"' -f kumar.awk File.csv

kumar.awk:
Code:
BEGIN {
   FS=OFS=","
}

{
   a=$2
   gsub(q, "", a); if (a+0 > 10) print
}

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: Page number with total number of pages, EG Page 1 of 5

So I've worked how to add page numbers based on regex. It's using the footer text. How do we get the total amount added so we have page number with the total number of pages? Desired output: Page No:1 of 5 Thanks in advance. (15 Replies)
Discussion started by: tugar
15 Replies

2. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

3. UNIX for Dummies Questions & Answers

Bash Floating Number Variables Comparision

I am trying to compare the floating number variables but i am receiving an error, can you please help what is wrong. Thank you. #!/bin/bash var1=100.25 var2=100.25 if (( $var1 == $var2 )); then echo "Matching" else echo "Not Matching" fi Error: ./number.sh: line... (6 Replies)
Discussion started by: Ariean
6 Replies

4. Shell Programming and Scripting

awk comparision between 2 files and substitution in third

Hi All, I have two files in the following format. File 1 : 1044|1|20121031|2910039.4|MR|201210|G1044|E 1082|2|20121031|1664662.84|MR|201210|G1082|E 1696|3|20121031|190801.5|MR|201210|G1696|E 1824|4|20121031|196350|MR|201210|G1824|E 1900|5|20121031|221447.8|MR|201210|G1900|E File 2 :... (7 Replies)
Discussion started by: nua7
7 Replies

5. Shell Programming and Scripting

Awk comparision

Hi Everyone I am new to Unix shell scripting Can anyone please explain me in detail how this command works awk -F@ 'NR==FNR{A=$2;next}$3 in A{$3=A}1' file2 file1 The above command I got it from this forum, but unable to implement it as I am not getting how this works:mad: I... (3 Replies)
Discussion started by: Vijay90
3 Replies

6. Shell Programming and Scripting

AWK print number of records, divide this number

I would like to print the number of records of 2 files, and divide the two numbers awk '{print NR}' file1 > output1 awk '{print NR}' file2 > output2 paste output1 output2 > output awl '{print $1/$2}' output > output_2 is there a faster way? (8 Replies)
Discussion started by: programmerc
8 Replies

7. Shell Programming and Scripting

awk: string followed by tab comparision

Hi all, Currently i am using if( $0~/ NOT / && $0~/ NULL /) { ................. } to check if the input record contains "NOT" and "NULL". But in some cases "NOT" and "NULL" are preceded and followed by tab. How do i find compare for these fields as well? (3 Replies)
Discussion started by: ysvsr1
3 Replies

8. Shell Programming and Scripting

File comparision with AWK / SED

Hi all I need to compare two separate product lists that are changed weekly. New products are added, old products are removed and prices change. I have found various Windows programs that do this function but it's not as clean as I like and just wondered if there was a simpler way with... (1 Reply)
Discussion started by: mrpugster
1 Replies

9. Shell Programming and Scripting

Range of records using comparision \awk

Hi Gurus, I have to fetch the records from a logs as per the time stamp . I am comfortable to use awk and sed in the script . But the logic to fetch the records as per comparison is the problem. $cat my_log.log <Jul 30, 2010 7:01:12 AM EEST> <Error> <WebLogicServer> <Jul 30, 2010 8:04:12 AM... (3 Replies)
Discussion started by: posix
3 Replies

10. Shell Programming and Scripting

while - comparision

Hi, Please find the attached scriplet and suggest me to fix the bug in this. ----------------------------------- noofdirs=`ls *.tar | wc -l` if ; then let i=1 while ( $i <= $noofdirs ) ; do echo $i mkdir $i file1=`ls *.tar | head -1` mv $file1 $i i =... (2 Replies)
Discussion started by: sharif
2 Replies
Login or Register to Ask a Question