Computing.Net > Forums > Programming > AWK in bash script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

AWK in bash script

Reply to Message Icon

Name: Rovinrac
Date: November 15, 2006 at 20:17:12 Pacific
OS: XP
CPU/Ram: 1g
Comment:

I have a variable $len containing a number in inches and a variable $conv containing the inch to cm conversion factor.
1in = 2.54cm

I am trying to get a command that will do:
$len*$conv giving a CM value rounded to two decimal places.

I have tried using:
echo | awk '{s = $len*$conv; printf "%5.2f\n", s}'

It does not like the variable useage.

The other issue I have is I need to align the decimal on the 35th character on the screen:

Assuming two decimal places:
awk ' { printf("%37.2f\n", $1) } '
This command will work accept like the previous it does not accept variables, only files which will not work for me.

Thanks for any help



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: November 15, 2006 at 23:25:47 Pacific
Reply:

There are several ways to embed shell variables in awk scripts and to pass shell variables to awk scripts. Take a look at this link:

http://www.tek-tips.com/faqs.cfm?fi...


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: AWK in bash script

bash script using awk www.computing.net/answers/programming/bash-script-using-awk/19581.html

Bash script to start application www.computing.net/answers/programming/bash-script-to-start-application/18255.html

Bash script help www.computing.net/answers/programming/bash-script-help/10720.html