regex - Awk gensub transformation -


echo "0.123e2" | gawk '{print gensub(/([0-9]+\.[0-9]+)e([0-9]+)/, "\\1 * 10 ^ \\2", "g")}' 

gives me "0.123 * 10 ^ 2" result expected. there way tell calculate term "12.3" ?

in general: there way modify/transform matches (\\1,\\2,...)?

it easier perl:

perl -pe 's/(\d+\.\d+e\d+)/ sprintf("%.1f",$1) /ge' filename 

with test data:

echo '0.123e2 xyz/$&" 0.3322e12)282 abc' | perl -pe 's/(\d+\.\d+e\d+)/ sprintf("%.1f",$1) /ge' 12.3 xyz/$&" 332200000000.0)282 abc 

with awk:

awk '{        while ( match( $0, /[0-9]+\.[0-9]+e[0-9]+/ ) > 0 ) {        num = sprintf("%.1f", substr( $0, rstart, rlength ) )        sub( /[0-9]+\.[0-9]+e[0-9]+/, num )       }        print $0     }' filename 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -