LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-03-2008, 06:52 PM   #1
UnixKiwi
LQ Newbie
 
Registered: Dec 2006
Posts: 28

Rep: Reputation: 15
awk '$2 == "NA" ... error


Hi I am trying to extract a subset of a dataset where the selection criteria is that the second column equals NA (all other options are numerical, NA is the only option containg letters).

The following script has worked for me previously on a much older unix machine but refuses to work for me now

awk '$2=="NA" {print $0}' newdat > temp

It seems that it won't recognise NA as it will work when I substitute one of the numbers in the place of NA (but of course it extracts the wrong data). I also used to be able to achieve similiar the same thing by using

awk '$2 > 99999999 {print $0}' newdat > temp

where 99999999 exceeded the highest numerical value in column 2. Unfortunately this does not work anymore either.

Can anyone see what I am doing wrong?
 
Old 02-03-2008, 07:43 PM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
you might want to try $2 ~ /NA/, if not show your sample data file
 
Old 02-03-2008, 09:05 PM   #3
UnixKiwi
LQ Newbie
 
Registered: Dec 2006
Posts: 28

Original Poster
Rep: Reputation: 15
Nup, still doesn't work

Sample Data

30448 992 30432 2 275 275 275 21 275 1994 1989 1993
10276 9929 9347 2 275 89 275 275 2004 2002 2000
10275 NA 9610 1 275 275 89 275 275 2004 2002 2001
37563 99999 36692 2 152 275 152 152 275 2002 2000 2000
37732 NA 36692 2 152 275 152 152 275 2002 2000 2000
 
Old 02-03-2008, 09:09 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
That's odd, the following works for me:
Code:
$ cat data
30448 992 30432 2 275 275 275 21 275 1994 1989 1993
10276 9929 9347 2 275 89 275 275 2004 2002 2000
10275 NA 9610 1 275 275 89 275 275 2004 2002 2001
37563 99999 36692 2 152 275 152 152 275 2002 2000 2000
37732 NA 36692 2 152 275 152 152 275 2002 2000 2000
$ awk '$2 ~ /NA/ {print $0}' data
10275 NA 9610 1 275 275 89 275 275 2004 2002 2001
37732 NA 36692 2 152 275 152 152 275 2002 2000 2000
What version of awk are you running?
Code:
$ awk --version
GNU Awk 3.1.5
Copyright (C) 1989, 1991-2005 Free Software Foundation.
 
Old 02-04-2008, 05:23 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by UnixKiwi View Post
Nup, still doesn't work

Sample Data

30448 992 30432 2 275 275 275 21 275 1994 1989 1993
10276 9929 9347 2 275 89 275 275 2004 2002 2000
10275 NA 9610 1 275 275 89 275 275 2004 2002 2001
37563 99999 36692 2 152 275 152 152 275 2002 2000 2000
37732 NA 36692 2 152 275 152 152 275 2002 2000 2000
This feature of awk is so basic and next to trivial that
I strongly doubt any implementation would have broken it.

I'd be looking at my input data more closely, and check
whether something sill is going on there, and awk for example
sees everything as ONE long line, or can't see the the fields
because a unicode character for space snuck in that's not
part of your locale ....


Cheers,
Tink
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
error: Error for wireless request "Set Mode" (8B06) : invalid argument "roaming" penguin chick Linux - Wireless Networking 5 08-22-2008 01:16 PM
upgrade to kernel 2.6.16.1 : "make bzImage" print "parse error" math_physics Red Hat 2 06-29-2007 11:04 PM
Replacing "function(x)" with "x" using sed/awk/smth Griffon26 Linux - General 3 11-22-2006 10:47 AM
"mythtv-setup" giving "Session management error: Authentication Rejected" Mitchua Ubuntu 0 10-09-2005 04:32 PM
FC4 install errors, "diabling IRQ #10" "nobody cares" error message??? A6Quattro Fedora 6 07-20-2005 12:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration