Is there a way in awk—gawk most likely—to set the record separator RS
to empty value to process each character of a string as a separate record? Kind of like setting the FS
to empty to separate each character in its own field:
$ echo abc | awk -F '' '{print $2}'
b
but to separate them each as a separate record, like:
$ echo abc | awk -v RS='?' '{print $0}'
a
b
c
The most obvious one:
$ echo abc | awk -v RS='' '{print $0}'
abc
didn't award me (as that one was apparently meant for something else per GNU awk documentation).
Am I basically stuck using for
etc.?
EDIT:
@xhienne's answer was what I was looking for but even using that (20 chars and a questionable variable A
:):
$ echo abc | awk -v A="\n" -v RS='(.)' -v ORS="" '{print(RT==A?NR:RT)}'
abc4
wouldn't help me shorten my earlier code using length
. Then again, how could I win the Pyth code: +Qfql+Q
:D.