RosettaCodeData/Task/Reverse-a-string/AWK/reverse-a-string-3.awk

12 lines
196 B
Awk

# Usage: awk -f reverse.awk -v s=Rosetta
function rev(s, i,a,r) {
split(s, a, "")
for (i in a) r = a[i] r
return r
}
BEGIN {
if(!s) s = "Hello, world!"
print s, "<-->", rev(s)
}