20251218-Linux skills

daily
Linux
Author

Ryan Sun

Published

2025-12-18

Linux skills

# print a file and show only two decimal digits for floating-point numbers
awk 'BEGIN{FS=OFS="\t"} {
    for(i=1; i<=NF; i++) {
        if ($i ~ /^[-+]?[0-9]*\.?[0-9]+$/ && $i ~ /\./) {
            $i = sprintf("%.2f", $i)
        }
    }
    print
}' data.tsv | head | column -t
Back to top