2015/06/25

Divide with floating point

awk 'BEGIN {printf "%.2f \n", (11.226 - 8.342)/11.226*100}'
awk 'BEGIN {print (11.226-8.342)/11.226*100}'

Rounding up works by default:
awk 'BEGIN {printf "%.3f \n", (11.226 - 8.342)/11.226*100}'

2015/06/12

Filter STDERR only

$ cat warn.pl
#!/usr/bin/env perl
print STDERR "warnings all over the place\n";
print STDOUT "standard output to file descriptor 1\n";

$ exec 3>&1; ./warn.pl 2>&1 >&3 3>&- | awk '{print $5}' 3>&-; exec 3>&-
standard output to file descriptor 1
place