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
Covert Channels Evaluation Framework 0.1 (Default branch) iBot Software Releases - RSS News 0 05-21-2008 09:40 PM
Standard Data Sets for CEP/IDS Evaluation iBot Complex Event Processing RSS News 0 08-01-2007 03:50 AM
equation calculation on Unix robbinGlasses UNIX for Dummies Questions & Answers 4 11-16-2006 07:13 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 11-22-2007
srdgeo srdgeo is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 2
AWK equation evaluation.

Hi,

Is there a way to evaluate an equation contained in a string within an AWK script?

For example:
A = "(5*2)-1" (this equation is read from a file and varies line by line)

In this example, I can't see any way to get an answer of 9 unless I do:

cmd = "awk 'BEGIN{print "A"}'"
cmd | getline A

The above method works fine but it's rather slow when dealing with large files!

Does anybody know of a better way of achieving the same result within the main AWK script?

Any help and advice appreciated.

Steve
  #2 (permalink)  
Old 11-22-2007
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 717
Hi.

Many interpreted languages have an eval feature, e.g. snobol, perl,.

I don't know of one for awk, but I'd be happy to learn of one ... cheers, drl
  #3 (permalink)  
Old 11-22-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
something educational to read up on....
  #4 (permalink)  
Old 11-23-2007
srdgeo srdgeo is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 2
Quote:
Originally Posted by vgersh99 View Post
something educational to read up on....

Thanks for your help! The modified calc3 code does exactly what I want and is 15 times faster than the method I was using!
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 02:40 AM.


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