linux - how to calculate percentage in shell -


i calculate percentage in shell. can't it. script is

#!/bin/bash #n1=$(wc -l < input.txt) #input.txt text file 10000 lines n1=10000 n2=$(awk '{printf "%.2f", $n1*0.05/100}') echo 0.05% of $n1  $n2 

it neither showing value nor terminating when executing script.

awk give n1 illegal field name if that, it's inside single quotes. also, avoid awk keep reading stdin should pass /dev/null file. then:

n2=$(awk -v n1="$n1" 'begin {printf "%.2f", n1*0.05/100}' /dev/null) 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -