Quick actions

cmd+k|ctrl+k

Navigation

Languages

awk scripting

Snippet info

Language

Bash

Visibility

public

Author

rajivm1991

Created

2021-08-21T09:09:00.187905Z

Updated

2021-10-04T03:01:26.45735Z

cat > round.awk << EOF
func round(n) {
    n = n + 0.5
    n = int(n)
    return n
}
/^(b|c|d)/ {print \$1,\$2,round(\$2)}
EOF

cat > input.txt << EOF
a 0.3
b 0.5
c 0.9
d 1.0
e 1.2
EOF

echo "input.txt"
echo "========="
cat input.txt

echo
echo "round.awk"
echo "========="
cat round.awk

echo
echo "awk -f round.awk input.txt"
echo "=========================="
awk -f round.awk input.txt

rm round.awk input.txt
INFO