The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
absolute path Kirichiko UNIX for Dummies Questions & Answers 2 10-03-2007 07:30 AM
get absolute filename mainegate Shell Programming and Scripting 0 08-21-2007 01:59 PM
absolute path filedeliver High Level Programming 4 06-05-2007 06:18 PM
Getting absolute value ksh icyhot UNIX for Dummies Questions & Answers 3 03-30-2006 07:05 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-11-2005
placroix1 placroix1 is offline
Registered User
  
 

Join Date: May 2005
Posts: 7
Absolute value

Is there a function in awk to get the absolute value of a-b which can be negative or positive, I just care for the absolute value...
  #2 (permalink)  
Old 05-11-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
echo '-12' | nawk '{ print ($1 >= 0) ? $1 : 0 - $1}'
  #3 (permalink)  
Old 05-11-2005
placroix1 placroix1 is offline
Registered User
  
 

Join Date: May 2005
Posts: 7
Thanks 80)
  #4 (permalink)  
Old 10-05-2005
LouPelagalli LouPelagalli is offline
Registered User
  
 

Join Date: May 2005
Posts: 11
Thanks vgersh99, it works for me too!
  #5 (permalink)  
Old 12-04-2007
ahjiefreak ahjiefreak is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 132
Hi vgersh99,

I saw this post and I wonder if I have an associative array for calculate an operation; how abs would work in this case.

Assume;

I have
count[$1]=$2-$1;

If I apply the one you suggested in earlier post,

can it be turned to;

count[$1]= ($4-$5)*(0.05);
if(count[$1]>=0){
count[$1]=count[$1];}
else
count[$1]=0-count[$1];


Please advise. Really hope to hear from you soon! Thanks

-Jason
  #6 (permalink)  
Old 12-04-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
Quote:
Originally Posted by ahjiefreak View Post
Hi vgersh99,

I saw this post and I wonder if I have an associative array for calculate an operation; how abs would work in this case.
sure, why not!
Quote:
Originally Posted by ahjiefreak
Assume;

I have
count[$1]=$2-$1;

If I apply the one you suggested in earlier post,

can it be turned to;


count[$1]= ($4-$5)*(0.05);
if(count[$1]>=0){
count[$1]=count[$1];}
else
count[$1]=0-count[$1];

Code:
   count[$1]= ($4-$5)*(0.05)
   if(count[$1]<0) count[$1]=0-count[$1]

Quote:
Originally Posted by ahjiefreak

Please advise. Really hope to hear from you soon! Thanks

-Jason
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:33 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0