Tuesday, October 2, 2007

Unix Command Samples - awk

Remove first 3 lines in a file:
$cat bearish.htm | awk 'NR>3'

Rounding Number:
Need to be able to round numbers in bash to the nearest whole number? You can use a single line of code in AWK to do the job. For example, the following code will make the number 29.498398 round up to 29.50:

$ echo 29.498398 | awk '{ rounded = sprintf("%.2f", $1); print rounded }'
29.50

No comments: