awk Help - Comparison Operator problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk Help - Comparison Operator problem
# 1  
Old 11-16-2012
awk Help - Comparison Operator problem

Hi,

I've tried searching through the forum but I've drawn a blank so i'm going to post here. I'm developing a number of checks on a CSV file, trying to find if any are greater than a max limit. I'm testing it by running it from a command line.

The file I'm testing has 8 records. When I perform a print of the length of the field I want to check I get this:
Code:
z:\clientfiles>awk -F, '{print length($1)}' 131112_143889b.csv
4
3
3
3
3
3
3
0

When I use the Equal operator as a check, I return the results I expect:
Code:
z:\clientfiles>awk -F, 'length($1) == 4 {print length($1)}' 131112_143889b.csv
4

But when I use the Greater than or Equal to operator, I don't understand why I'm not getting back any records?
Code:
z:\clientfiles>awk -F, 'length($1) >= 4 {print length($1)}' 131112_143889b.csv

z:\clientfiles>awk -F, 'length($1) >= 0 {print length($1)}' 131112_143889b.csv

z:\clientfiles>

I've tried using the int() and +0 as suggested in other answers in case one of the figures is being treated as a string, but I've hit a wall and not sure what to do next? Can anyone suggest anything? Apologies if I've made a really beginner mistake and can't see it.
# 2  
Old 11-16-2012
Not reproducible on my linux/mawk:
Code:
$ awk -F, 'length($1) >= 0 {print length($1)}' file
4
3
2
0

Any invisible chars in your code/data?
# 3  
Old 11-21-2012
thanks for trying RudiC, no there's no invisible characters. Still having same problems so I'm going to check each record individually instead.
# 4  
Old 11-21-2012
pls. post the output of od -An -tx1 131112_143889b.csv , maybe with the file reduced to some few lines.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using like operator in awk if condition

Hello All, I have developed a script which selects a particular filed from a file ,trims it,searches for a particular pattern and then mail it when found. cat test_file.txt |sed -n '5,$p'|sed -e 's/ //g'|awk -F'|' '{if ($4 !="Alive") print $1,$2,$3,$4}' >> proc_not_alive.txt It is... (4 Replies)
Discussion started by: karthik adiga
4 Replies

2. UNIX for Dummies Questions & Answers

awk if statement / equals operator

Hi, I was hoping someone could explain this please :) I'm using bash, scientific linux... and I don't know what else you need to know. With awk '{ if( 0.3 == 0.1*3) print $1}' file.dat nothing will be printed since apparently the two numbers do not equate. (Using 0.3 != 0.1*3 is seen... (4 Replies)
Discussion started by: Golpette
4 Replies

3. Programming

Problem with STL's std::set container parameter to the operator << ()

Hi, I have this following code which gives me error when compiling. The problem is happening at the point where I create a const_iterator inside the overloaded insertion operator (i.e) operator << () function. The template argument version of set is not correct I guess. Could anyone please pitch... (3 Replies)
Discussion started by: royalibrahim
3 Replies

4. UNIX for Dummies Questions & Answers

Magic numbers '&' operator problem

Hello everyone, on the man page of "magic(5)" There is explanation "&, to specify that the value from the file must have set all of the bits that are set in the specified value" . My question is that what is the difference between '&' and equal operator '=' ? I tested it with file... (6 Replies)
Discussion started by: segmentation
6 Replies

5. Shell Programming and Scripting

Awk with or and not operator

awk -F '/' '{ if (($2!="30") print }' f.dat > date_mismatch.dat The above command is giving the desired results But I would want use Or in the above but it is returning the complete file awk -F '/' '{ if ($2!="30"||$2!="31") print }' f.dat > date_mismatch.dat Have tried the... (1 Reply)
Discussion started by: infernalhell
1 Replies

6. Shell Programming and Scripting

Comparison and editing of files using awk.(And also a possible bug in awk for loop?)

I have two files which I would like to compare and then manipulate in a way. File1: pictures.txt 1.1 1.3 dance.txt 1.2 1.4 treehouse.txt 1.3 1.5 File2: pictures.txt 1.5 ref2313 1.4 ref2345 1.3 ref5432 1.2 ref4244 dance.txt 1.6 ref2342 1.5 ref2352 1.4 ref0695 1.3 ref5738 1.2... (1 Reply)
Discussion started by: linuxkid
1 Replies

7. UNIX for Dummies Questions & Answers

problem with pipe operator

hi i am having issues with extra pipe. i have a data file and i need to remove the extra pipe in the(example 4th and 7thline) in datafile. there are many other line and filed like this which i need to remove from files. The sample data is below: 270 31|455004|24/03/2010|0001235|72 271... (3 Replies)
Discussion started by: abhi_n123
3 Replies

8. UNIX for Dummies Questions & Answers

Problem unary operator expected

I get the following error ./get_NE05: line 42: while do echo ${STRING_NAME} J=1 if ; then EXT=0$I else EXT=$I fi while do echo $I-$J #calculating last occurrence OCCURRENCE=`grep -io "${STRING_NAME}"... (3 Replies)
Discussion started by: f_o_555
3 Replies

9. Shell Programming and Scripting

Problem with here doc operator in FTP script

Hello folks, I am facing a problem with the following korn shell script snippet: ftp -n -i -v <<EOF print -p open $CURR_HOST print -p user $USER $PASSWD print -p binary print -p cd /mydir/subdir/datadir print -p get $FILENAME print -p bye EOF exit It gives me the following... (3 Replies)
Discussion started by: Rajat
3 Replies

10. Programming

Problem about c++ new operator

#include <iostream.h> class test { private: int i; public: inline test(int m) { i = m; } inline int get_i() { return i; } }; int main() { test * a = new test(2); (3 Replies)
Discussion started by: xbjxbj
3 Replies
Login or Register to Ask a Question