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
Post a Comment