swaping of first 2 words in every line using sed
sed -e "s/\([^ ]*\) *\([^ ]*\)/\2 \1 /g" filename
swaping of last 2 words (6<->5) in every line using sed
sed -e "s/\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\)/\1 \2 \3 \4 \6 \5 /g" filename
Reference: http://www.unix.com/shell-programming-scripting/67000-swaping-first-2-words-every-line-using-sed.html
No comments:
Post a Comment