When looking for a quick way of right trimming a text string, I found the following wiki page:
In the chapter about AWK it gives 2 sets of examples:
ltrim(v) = gsub(/^[ \t]+/, "", v)
rtrim(v) = gsub(/[ \t]+$/, "", v)
trim(v) = ltrim(v); rtrim(v)
or
function ltrim(s) { sub(/^[ \t]+/, "", s); return s }
function rtrim(s) { sub(/[ \t]+$/, "", s); return s }
function trim(s) { return rtrim(ltrim(s)); }
The lower example is entirely familiar and works fine, but the first example looks different to anything I have seen in 20 years of AWK programming. It looks like a really useful quick way to define and use a function in one line. I can't get this syntax to work in GNU Awk 3.1.5 - so is it something which was introduced in a more recent version?
I would be grateful of a real working example if anyone is familiar with this syntax.