gawk to remove last character in a line or string

I am outputting a line like this

print $2 "/" $4

The last character though is a ":" and I want to remove it. Is there any neat way to remove it? Or am I forced to do something like this:

print $2 "/" substr($4, 1, length($4) - 1)

Thanks.

You can use sub or gsub - but it is not any "neater" than any other function, IMO.

print $2 "/" gsub(":$", "", $4, )

gsub returns the number of the substitutions - I don't think that's what the OP is after.

Thanks.

I was hoping there would be something like I would do in shell:

 echo ${var%?}

or

 echo ${var%:}

or similar.

---------- Post updated at 11:46 AM ---------- Previous update was at 11:40 AM ----------

True. He probably meant:

gsub(":$", "", $4, ); print $2 "/" $4

If $4 contains a number (with or without leading spaces) and then the : at end, you could write something like print $2 "/" $4+0 .

Yup, my post was in error. Should be:

gsub(":$", "", $4 )

print $2 "/" $4

gsub is unnecessary here. sub is enough.