Unix 如何使用sed交换通过连字符连接的两个单词

Unix 如何使用sed交换通过连字符连接的两个单词,unix,sed,Unix,Sed,我需要使用扩展正则表达式交换两个连字符连接的单词,例如,super-fast->fast-super 我已经通过互联网进行了搜索,并找到了解决方案: sed -r "s/^\(.*\) \(.-\) \(.*\)/\3 \2 \1/" inputfile 不起作用。如果您确实知道您将有一个-: $ sed -E 's/(.*)-(.*)/\2-\1/' <<< 'super-fast' fast-super $sed-E's/(.*)-(.*)/\2-\1/'sed“s/^

我需要使用扩展正则表达式交换两个连字符连接的单词,例如,
super-fast
->
fast-super

我已经通过互联网进行了搜索,并找到了解决方案:

sed -r "s/^\(.*\) \(.-\) \(.*\)/\3 \2 \1/" inputfile

不起作用。

如果您确实知道您将有一个
-

$ sed -E 's/(.*)-(.*)/\2-\1/' <<< 'super-fast'
fast-super
$sed-E's/(.*)-(.*)/\2-\1/'
sed“s/^\(.*)-\(.*)$/\2-\1/”输入文件
<代码>sed“s/\([[:alpha:]\{1,\}\)-\([[:alpha:]\{1,\}\)/\2-\1/”输入文件
$ sed -E 's/(.*)-(.*)/\2-\1/' <<< 'one-two-three'
three-one-two
$ sed -E 's/([^-]*)-(.*)/\2-\1/' <<< 'one-two-three'
two-three-one