![将两个字符串之间的字符移动到行尾](https://linux22.com/image/1577496/%E5%B0%86%E4%B8%A4%E4%B8%AA%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%B9%8B%E9%97%B4%E7%9A%84%E5%AD%97%E7%AC%A6%E7%A7%BB%E5%8A%A8%E5%88%B0%E8%A1%8C%E5%B0%BE.png)
我需要(在文本文件中)将从“>”到“_”之间的所有字符移动到该行的末尾。
由此:
[[[>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
就地编辑文件。