LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-07-2008, 03:15 PM   #1
ryanlum
Member
 
Registered: Jul 2007
Posts: 47

Rep: Reputation: 15
Need help with nawk


hi all,

I got a file that got tonsof record. It looks like this

60175144442 020120732491661399 20080405000452 0
60175144443 020120732491661399 20080405000452 0
60175144444 020120732491661399 20080405000452 0

How am i able to use nawk to check whether the end of the column (column 4) is a 0 or another number?
 
Old 04-07-2008, 03:43 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Code:
awk '{ if ($4=="0") { print "yes" } else { print "no" } }'
Looks like telecoms records?
 
Old 04-07-2008, 03:52 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You can simply do something like this:
Code:
nawk '! $4 {printf "line %04d has zero\n",NR}' file
in this particular case the expression "! $4" evaluates to true if $4 is not different than zero (remember that in awk any non-zero numeric value or any non-empty string value is true, while any other value - zero or the null string - is false). A more explicit version is simply
Code:
nawk '{if ($4 == 0) printf "line %04d has zero\n",NR}' file
 
Old 04-07-2008, 04:02 PM   #4
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
1) Perhaps this should be in the "Programming" sub-forum.

2) If nwak is "standard", try $4 != "0" {print}
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
nawk question - addition of a column dazdaz Programming 1 02-19-2008 11:47 AM
Removing non-unique record in nawk omega71122 Linux - Software 4 05-03-2006 10:45 AM
Nawk output omega71122 Solaris / OpenSolaris 3 08-16-2005 03:40 PM
nawk not available raees Linux - Software 3 05-02-2005 03:49 PM
Nawk issues michedlp Programming 1 02-25-2004 07:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:04 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