![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| Problem in arithemetic operation | subin_bala | Shell Programming and Scripting | 3 | 04-23-2008 11:47 AM |
| Use of functions | amitrajvarma | Shell Programming and Scripting | 1 | 11-23-2007 06:52 AM |
| How to parse config variables from external file to shell script | pradsh | Shell Programming and Scripting | 2 | 07-09-2007 03:21 PM |
| Variables and functions | dfb500 | Shell Programming and Scripting | 4 | 05-21-2007 05:23 PM |
| arithemetic problem | anujairaj | UNIX for Dummies Questions & Answers | 9 | 05-01-2006 12:55 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
awk - arithemetic functions with external variables
I'm trying to get awk to do arithmetic functions with external variables and I'm getting an error that I cannot figure out how to fix. Insight would be appreciated Code:
money=$1
rate1=$(awk -F"\t " '/'$converting'/{print $3}' convert.table)
rate2=$(awk -F"\t" '/'$converted'/{print $3}' convert.table)
awk -F"\t" '{printf '$rate2'/'$rate1'*'$money'}'
OUTPUT awk: cmd. line:1: {printf 3.3513 awk: cmd. line:1: ^ unexpected newline or end of string |
|
||||
|
I'm not at a UNIX machine now, but this should work: Code:
money=$1
rate1=$(awk -F"\t " '/'$converting'/{print $3}' convert.table)
rate2=$(awk -F"\t" '/'$converted'/{print $3}' convert.table)
awk -F"\t" '{printf r2/r1*m}' r2=$rate2 r1=$rate1 m=$money
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|