How can I trim white space from a variable in awk?

You’re printing the result of the gsub, but gsub does an in-place modify of $2 instead of returning a modified copy. Call gsub, then print:

awk -F\, '{gsub(/[ \t]+$/, "", $2); print $2 ":"}'

Leave a Comment