Share your knowledge at the LQ Wiki.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org Absolute Value function in AWK
 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

 11-02-2009, 06:17 AM #1 bioinformatics_guy Member   Registered: Aug 2008 Posts: 54 Rep: Absolute Value function in AWK I was wondering if there was an absolute value function in awk? More specifically, I need it in a string of boolean operators. Right now I have: awk '{ if ( \$1 == 0 && \$2 != \$1 && [absolute value of \$1-\$2] <= 6 ) print }' But I don't know what I need to put in the brackets.
 11-02-2009, 06:31 AM #2 bioinformatics_guy Member   Registered: Aug 2008 Posts: 54 Original Poster Rep: I figured it out, but in case anyone was interested or has a similar problem, the line is: awk '{ if ( \$1 == 0 && \$2 != \$1 && ( \$1-\$2 >=0 ? \$1=\$2 : \$2-\$1 ) <= 6 ) print }'
 11-02-2009, 06:50 AM #3 geek.ksa Member   Registered: Jan 2009 Location: Dhahran, Saudi Arabia Distribution: RHEL 5 Posts: 42 Rep: Ummm one could implement an absoluteness function by simply: function abs(value) { if(value < 0) return value * -1 else return value } didn't test it but it should work :P
 11-02-2009, 07:05 AM #4 jlliagre Moderator   Registered: Feb 2004 Location: Outside Paris Distribution: Solaris 11.3, Oracle Linux, Mint Posts: 9,690 Rep: That might be simplified to: Code: ```function abs(value) { return (value<0?-value:value); }```

 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 Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post binarybob0001 Programming 12 06-16-2011 04:43 PM rajeshksv Linux - Newbie 1 08-07-2009 07:07 AM mcandy General 1 12-15-2008 12:21 PM intikhabalam Linux - General 4 07-29-2008 10:40 AM philosophia Programming 1 02-20-2007 05:53 PM

All times are GMT -5. The time now is 09:37 AM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -