exchange two words using sed in Linux

后端 未结 5 1695
旧巷少年郎
旧巷少年郎 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:18

    I start to make it with \s which means any whitespaces chars.
    I use it for match every words with [^\s]*which match with everything but not spaces.
    And I had \s* for match withspaces between words. And don't forget to rewrite a space in replacement.

    Look a this for an example:

    sed 's#\([^ ]*\)\s+#\1 #'
    

    ( I use # instead of /)

提交回复
热议问题