exchange two words using sed in Linux

后端 未结 5 1700
旧巷少年郎
旧巷少年郎 2021-01-26 04:08

guys! I am trying to exchange two words in a line but it doesn\'t work. For example: \"Today is my first day of university\" should be \"my is Today first day of university\"

5条回答
  •  离开以前
    2021-01-26 04:17

    Try this:

    sed -rn 's/(\w+\s)(\w+\s)(\w+\s)(.*)/\3\2\1\4/p' filename.txt
    

    -n suppress automatic printing of pattern space

    -r use extended regular expressions in the script

    \s for whitespace

提交回复
热议问题