Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have a variable $len containing a number in inches and a variable $conv containing the inch to cm conversion factor.
1in = 2.54cmI 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

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:

![]() |
![]() |
![]() |

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