Re: [1/2OT] something about sed
On Sun, Feb 26, 2012 at 4:30 PM, lina <email@example.com> wrote:
> sorry a bit off-topic,
> sed -e 's/\(<[^ ]*>\)\([ ]*\)\(<[^ ]*>\)/\3\2\1/g'
> GNU Linux is cool
> Linux GNU cool is
No here ...
> I don't know why
> $ echo "GNU linux is cool" | sed -e 's/\(<[^ ]*>\)\([ ]*\)\(<[^ ]*>\)/\3\2\1/g'
> GNU linux is cool
> It doesn't work.
Remove "<" and ">", from substitution, and sustitute * by "\+", and
you can use " *" without have to use "[ ]*"
sed -e 's/\([^ ]\+\)\( \+\)\([^ ]\+\)/\3\2\1/g'
or using extended regular expressions, you can remove all escape stuff :
sed -re 's/([^ ]+)( +)([^ ]+)/\3\2\1/g'
I hope this help