simple examples of how to

Friday, October 21, 2011

[AWK] how to print all string except one field?

If you want to print without 5-th field, you can brute forcely do

bruteforce:
  • echo "1 2 3 4 5 6 7 8 9" | awk '{print $1, $2, $3, $4, $6, $7, $8, $9}'
better way:
  • echo "1 2 3 4 5 6 7 8 9" | awk '{ for (i=1; i<=NF; i++ ) if( i != 5 ) print $i}'
simple cheating:
  • echo "1 2 3 4 5 6 7 8 9" | awk '{$5=""; print $0}'

No comments:

Post a Comment