How to awk
Good insitincts.
Also, for both of the posters so far in this thread - please don't
top-post. To save anyone else from having to untangle the top-posting
and wild snipping that's lead to this point, the original posting was:
and the answer is to get GNU awk (gawk) and use it's gensub() function:
$ echo "Paul loves Mary" | gawk '{print gensub(/(.*) (.*) (.*)/,"\\3 \\2
\\1","")}'
Mary loves Paul
Here's some substition examples to peruse if you like:
PS1> echo "abcbd" | gawk 'sub(/b/,"|&|")' a|b|cbd
PS1> echo "abcbd" | gawk 'gsub(/b/,"|&|")' a|b|c|b|d
PS1> echo "abcbd" | gawk '$0=gensub(/b/,"|&|","")' a|b|cbd
PS1> echo "abcbd" | gawk '$0=gensub(/b/,"|&|","g")' a|b|c|b|d
PS1> echo "abcbd" | gawk '$0=gensub(/(b)/,"|\\1|","")' a|b|cbd
PS1> echo "abcbd" | gawk '$0=gensub(/(b)/,"|\\1|","g")'
a|b|c|b|d
PS1> echo "abcbd" | gawk '$0=gensub(/(b)(c)/,"|\\2\\1|","g")'
a|cb|bd
Regards,
Ed.
|