Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > How to awk
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 19th October 07:00
paul bullack
External User
 
Posts: 1
Default How to awk



Hello, ist there anybody OUT there ? :-)


echo "Paul loves Mary" | sed "s/\([^ ]*\)\(.......\)\([^ ]*\)/\3\2\1/"

results "Mary loves Paul"

How is the awk syntax to do this ?

Thanks in advance, Paul
  Reply With Quote


 


2 19th October 07:00
mag gam
External User
 
Posts: 1
Default How to awk



echo "Paul loves Mary" | awk '{print $3,$2,$1 }'
  Reply With Quote
3 19th October 07:00
paul bullack
External User
 
Posts: 1
Default How to awk


Hello,

"Mag Gam" <magawake@gmail.com> schrieb im Newsbeitrag news:1156267407.960461.75640@i42g2000cwa.googlegro ups.com...
  Reply With Quote
4 19th October 07:00
xicheng jia
External User
 
Posts: 1
Default How to awk


awk's regex does not support back-reference, so \1 \2 \3 stuff is not
available in awk.

--
XC
  Reply With Quote
5 19th October 07:00
paul bullack
External User
 
Posts: 1
Default How to awk


Hi Jia,

can't believe it (:-), and what is the corresponding way in awk, if any

Paul


"Xicheng Jia" <xicheng@gmail.com> schrieb im Newsbeitrag
news:1156270937.145827.28050@75g2000cwc.googlegrou ps.com.
  Reply With Quote
6 19th October 07:01
ed morton
External User
 
Posts: 1
Default 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.
  Reply With Quote
Reply


Thread Tools
Display Modes




666