What is wrong with my awk code?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What is wrong with my awk code?
# 1  
Old 10-24-2014
What is wrong with my awk code?

Hi there, I am trying to select a number of lines based on the lat. lon columns in a file but my awk code gives me empty result.


Here is my file:

Code:
20100213 102212 33.1185 39.4078 2.9
20100214 141753 33.1058 39.9068 2.9
20100218 115828 33.1907 39.3575 2.9
20100225 220001 33.1932 39.9448 2.9
20100226 152045 32.0103 39.3327 2.9
20100228 204455 33.1685 39.3558 2.9
20100323 081029 33.9345 39.9825 2.9
20100328 074927 32.8845 38.7272 2.9
20100330 034504 33.159 38.4325 2.9
20100413 071614 32.959 38.698 2.9
20100427 221931 33.0723 39.4485 2.9
20100524 010333 33.1305 39.3832 2.9
20100928 222019 33.3445 38.938 2.9
20101012 145522 34.0737 38.3135 2.9
20101020 051633 34.7478 38.154 2.9
20101024 232138 34.6318 39.5025 2.9
20101102 141258 32.0048 39.6565 2.9
20110207 140450 33.4383 39.9757 2.9
20110219 140734 34.2425 38.343 2.9
20110227 081313 33.1547 39.3738 2.9

3rd column = LON, 4th column = LAT

I need to select events between 39.10 <= $4 <= 39.64 and 32.75 <= $3 <= 33.28

I know there are lines that satisfy these conditions in the files.

and my code:

Code:
cat latlon.dat | awk '($4 >= 39.10 && $4 <= 39.64) && ($3 >= 32.75 && $3 <= 33.28) {print $0}'

This just gives empty list.
# 2  
Old 10-24-2014
What is your OS and version? I get:
Code:
20100213 102212 33.1185 39.4078 2.9
20100218 115828 33.1907 39.3575 2.9
20100228 204455 33.1685 39.3558 2.9
20100427 221931 33.0723 39.4485 2.9
20100524 010333 33.1305 39.3832 2.9
20110227 081313 33.1547 39.3738 2.9

# 3  
Old 10-24-2014
Centos 5.8 and GNU Awk 3.1.5
# 4  
Old 10-24-2014
Hi.

Here are results from a CentOS / awk combination:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate arithmetic comparison, and filtering, awk.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C awk

FILE=${1-data1}

pl " Input data file $FILE:"
cat $FILE

pl " Results:"
awk '($4 >= 39.10 && $4 <= 39.64) && ($3 >= 32.75 && $3 <= 33.28) {print $0}' $FILE

exit 0

producing:
Code:
$ ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.32-358.23.2.el6.centos.plus.x86_64, x86_64
Distribution        : CentOS 6.4 (Final)
bash GNU bash 4.1.2
awk GNU Awk 3.1.7

-----
 Input data file data1:
20100213 102212 33.1185 39.4078 2.9
20100214 141753 33.1058 39.9068 2.9
20100218 115828 33.1907 39.3575 2.9
20100225 220001 33.1932 39.9448 2.9
20100226 152045 32.0103 39.3327 2.9
20100228 204455 33.1685 39.3558 2.9
20100323 081029 33.9345 39.9825 2.9
20100328 074927 32.8845 38.7272 2.9
20100330 034504 33.159 38.4325 2.9
20100413 071614 32.959 38.698 2.9
20100427 221931 33.0723 39.4485 2.9
20100524 010333 33.1305 39.3832 2.9
20100928 222019 33.3445 38.938 2.9
20101012 145522 34.0737 38.3135 2.9
20101020 051633 34.7478 38.154 2.9
20101024 232138 34.6318 39.5025 2.9
20101102 141258 32.0048 39.6565 2.9
20110207 140450 33.4383 39.9757 2.9
20110219 140734 34.2425 38.343 2.9
20110227 081313 33.1547 39.3738 2.9

-----
 Results:
20100213 102212 33.1185 39.4078 2.9
20100218 115828 33.1907 39.3575 2.9
20100228 204455 33.1685 39.3558 2.9
20100427 221931 33.0723 39.4485 2.9
20100524 010333 33.1305 39.3832 2.9
20110227 081313 33.1547 39.3738 2.9

I don't have a version of CentOS older than this.

Best wishes ... cheers, drl
# 5  
Old 10-24-2014
Hmm, interesting. I have tried the code on Ubuntu machine and it works. I wonder what is the problem with my Centos workstation.

Last edited by johankor; 10-24-2014 at 10:56 AM.. Reason: grammar
# 6  
Old 10-24-2014
What happens if you copy-paste the file content hat you posted here into a new file on your original CentOS 5.8 host and try again with this new file?
# 7  
Old 10-24-2014
Quote:
Originally Posted by Scrutinizer
What happens if you copy-paste the file content hat you posted here into a new file on your original CentOS 5.8 host and try again with this new file?
I also got suspicious that maybe my file was damaged (modified) somehow and copy/pasted the contents to a new file as you suggested, but it still doesn't work on Centos 5.8. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

What's wrong with my awk

file1: maximum_delay time: 102.794 ms maximum_delay time: 92.977 ms maximum_delay time: 98.895 ms maximum_delay time: 96.891 ms maximum_delay time: 86.966 ms maximum_delay time: 95.91 ms maximum_delay time: 98.921 ms maximum_delay time: 89.881 ms maximum_delay time: 92.931 ms... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

2. Shell Programming and Scripting

What is wrong with my code?

Hello, all Suppose my current directory has 3 files: file_1 file_2 file_3 I wrote the following codes: awk 'BEGIN{while("ls"|getline d) {myarray++}}; END{close("ls");for (i in myarray){print i, myarray}}' /dev/null I expect the output be like: 1 file_1 2 file_2 3 file_3 ... (7 Replies)
Discussion started by: littlewenwen
7 Replies

3. Shell Programming and Scripting

What's wrong with this awk?

I have a file and if I'm doing following action on that file it's coming up correctly awk -F"," '/DATA_TYPE/ { cnt += $3 } END { print " DATA_TYPE count=" cnt}' inter DATA_TYPE count=19593131 now if I'm changing same AWK, so that now it can accept variable, then it's somehow not working.... (3 Replies)
Discussion started by: manas_ranjan
3 Replies

4. Shell Programming and Scripting

what's wrong with my awk

echo "abc:bcd" |awk '{split($0,b,":");print "b" is good }' I want to "bcd" is good , anything is wrong with my, please don't change my thought with split, I just want to know what's wrong :o (1 Reply)
Discussion started by: yanglei_fage
1 Replies

5. Shell Programming and Scripting

What's wrong with this awk?

ZSCORE=$(awk "BEGIN {if($STDEVIATE>0) {print ZSCORER=$(awk "BEGIN{print (${ALL} - ${AVERAGE}) / ${STDEVIATE}}")}else print "0"}") awk: fatal: division by zero attempted awk: BEGIN {if(0==0) {print ZSCORER=}else print 0} awk: ^ syntax error ALL=9 STDEVIATE=0... (2 Replies)
Discussion started by: SkySmart
2 Replies

6. Shell Programming and Scripting

awk... what is wrong?

Hi there, what is wrong with this? grep ">>" alarms_temp | awk '{print substr($5, 2), $7}' | read var1 var2 echo "$var1" echo "$var2" Both variable are empty, but if i run: grep ">>" alarms_temp | awk '{print substr($5, 2), $7}' I have: 0 9 as a result. (2 Replies)
Discussion started by: marimovo
2 Replies

7. Shell Programming and Scripting

What's wrong with this code?

Trying to do a file count on files between a specific date. I entered the following command, but it's not working: find . -type f \( -newer startdate -a ! -newer enddate \) -exec "ls -l | wc -l" {} \; lil help? :D (4 Replies)
Discussion started by: bbbngowc
4 Replies

8. Shell Programming and Scripting

What is wrong with this code

I just wanted to assign the filename to a variable filename="abc" datestrng=`date +%Y%m%d` filextn="txt" "LOCAL_FILE"${i}=${filename}"_"${datestrng}"."${filextn} echo "LOCAL_FILE"${i} I get the following error on 2nd last line ksh: LOCAL_FILE1=abc_20081114.txt: not... (3 Replies)
Discussion started by: mqasim
3 Replies

9. Shell Programming and Scripting

What's wrong with this code?

Hello all, Can someone tell me why I'm getting an error in the following code: export return_code="$?" if then echo "load_shaw.sas failed." exit else echo "Trigger the next script..." # /path/to/next/script fi I get an error... (3 Replies)
Discussion started by: mmignot
3 Replies

10. UNIX for Dummies Questions & Answers

What is wrong with this code?

Hello everyone, can somebody tell me what is wrong with this code: while true do java myTime > myTime.log sleep 60 done I get the following error: ./myTime: Syntax error at line 1 : `while' is not matched. Thanks in advance! (6 Replies)
Discussion started by: Lem2003
6 Replies
Login or Register to Ask a Question