AWK: formating number without printf

Hello,

I wrote a script that does lot of things, and I would like to change the format of a number but without printing it now (so I don't want to use printf as it will print the value immediately).

Schematically here is what I have:

awk 'BEGIN{number=0.01234567}
$1==$2{$3=number}
{print}' myfile

I would like to have my output with the format 1.234567E-02, but of course the BEGIN part cannot be changed. The problem with using printf is that the lines matching $1==$2 don't have all the same number of elements, or the same spacing...

Every suggestion is very welcome.

Thanks

This works from the command line:

-bash-3.00$ myvar=$(printf "%1.2f" 1.35811);echo $myvar;
1.36

Of course alter it however you see fit! :slight_smile:

Unfortunately I cannot not assign a variable like that in my awk script ( ^ syntax error)...

Use sprintf().

cfajohnson - he knows everything!! I aspire to be like him :stuck_out_tongue:

Awesome!!! :slight_smile:

:b: