LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-29-2011, 04:19 AM   #1
mauludi
LQ Newbie
 
Registered: Jan 2010
Posts: 21

Rep: Reputation: 0
limitation of "&&" mark in awk


Dear All,

In writing a small awk script code,I used conditional like below:

$1<=m && $1>=(m-3.2) && $2>=0.01 {co=co+1}

it works well, but when I add one more conditional like:

$1<=m && $1>=(m-3.2) && $2>=0.01 && $2<0.3 {co=co+1}

it does not work.
is there a limitation in usage of "&&" ?
is there any solution of that?

thank you in advance
with best wishes,
 
Old 04-29-2011, 04:57 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

Using (gnu) awk, that should work.

Are you sure (some of) the $2 values are smaller then 0.3?
 
Old 04-29-2011, 05:01 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Nope. There is no limitation. Please elaborate what "it does not work" means: are you getting some error message or it simply doesn't behave as expected? Which version of awk are you using and on what OS? I've tried your code on my system and it works flawlessly.
Code:
$ cat /etc/*release
openSUSE 11.3 (i586)
VERSION = 11.3
$ awk --version
GNU Awk 3.1.6
The only caveat is that in a chain of logical operators, if one of the first conditions is false, the remaining ones are not evaluated.

Last edited by colucix; 04-29-2011 at 05:02 AM.
 
Old 04-30-2011, 12:18 AM   #4
mauludi
LQ Newbie
 
Registered: Jan 2010
Posts: 21

Original Poster
Rep: Reputation: 0
Dear All

I am so sorry for not careful checking. It works actually.

thank you for your reply.
 
Old 04-30-2011, 12:57 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Glad you caught it ... please mark as SOLVED.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Need solution to Sed problem. Want to match "&" but not "&amp;" tells Linux - General 14 02-05-2012 09:59 AM
[SOLVED] "Insert" & "Delete" key returns "~" in a terminal. sharky Linux - General 15 04-26-2011 09:36 AM
SynCE & ppc-6800 (Mogul): I get no /dev/ttyUSB0 & "Hal reports no devices connected" lumix Linux - Hardware 3 07-03-2008 11:03 AM
removing "\r" while using command cp , grep & awk rakesh.tandur Linux - Newbie 4 05-09-2008 07:02 PM
Segmentation fault on toplevel = XtVaAppInitialize(&app, "Email", NULL, 0, &argc, cbranje Programming 0 02-19-2005 01:06 PM


All times are GMT -5. The time now is 04:43 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration