将两个字符串之间的字符移动到行尾

将两个字符串之间的字符移动到行尾

我需要(在文本文件中)将从“>”到“_”之间的所有字符移动到该行的末尾。

由此:

[[[>AVA_M427014_
MAKNISRTAQMRVAIEEL

>AVB_L427D15_
MSGATSRTGNLRKEIEELVLT

>GVB_F83R906_
MAKIRANIPELLCAGVT

s004
5039.1
40403

更改为:

[[[>M427014_AVA_
MAKNISRTAQMRVAIEEL

>L427D15_AVB_
MSGATSRTGNLRKEIEELVLT

>F83R906_GVB_
MAKIRANIPELLCAGVT

s004
5039.1
40403

答案1

sed 's/>\([^_]*_\)\(.*\)$/>\2\1/' file
#    s/                  /     / search and replace
#                                search for
#      >                         literal >
#       \(      \)\(  \)         two blocks
#         [^_]*                  anything but _, zero or more characters
#              _                 literal _
#                   .*           zero or more characters
#                       $        end of line
#                                replace with
#                         >      literal >
#                          \2\1  the second block, then the first block

用于sed -i就地编辑文件。

相关内容