Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
@MensaWater: It worked, but why this sort of behaviour? I remember, I had done similar tests earlier, and they were doing exactly what I wanted. For example, if I simply test $3 > 0.10, it gives appropriate result, but if I use same thing in an if statement, it doesn't!
@jpollard: It worked fine, but is there any difference with use of ";" or without using it? An explaination would be helpful for me.
The above says, if expression is true, do nothing, ie everything between the last bracket and the semi colon is what is to be executed once the test is true.
@MensaWater: It worked, but why this sort of behaviour? I remember, I had done similar tests earlier, and they were doing exactly what I wanted. For example, if I simply test $3 > 0.10, it gives appropriate result, but if I use same thing in an if statement, it doesn't!
The input can be string, integer or floating point. If you review the awk man page it will tell you that it determines which type you're using but then also notes you can put the 0 in front of the variable to insure it treats it as a numeric (integer or floating point) as opposed to string.
Various programs do this kind of thing and may do it differently but it is always best if there is a way to tell it the type explicitly as there is in awk to go ahead and do it to remove ambiguity. It may be awk saw the "." as string so treated the numbers before and after it as part of the string and with different quoting it would have forced it to see the entire thing as floating point. However since there is the easy method of forcing it to see it as numeric I wouldn't bother looking further but you can feel free to do so.
A "statement" is either a block statement - starting with "{" and ending with }" or a simple statement, an assignment or function call and terminated with a newline or a ";" in the case of a multi-statement line.
In your case the "if(...);" was one statement, followed by another "print $3"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.