0

I need to move (in a text file) all the characters between ">" up to and including "_" to the end of that line.

From this:

[[[>AVA_M427014_
MAKNISRTAQMRVAIEEL

>AVB_L427D15_
MSGATSRTGNLRKEIEELVLT

>GVB_F83R906_
MAKIRANIPELLCAGVT

s004
5039.1
40403

to this:

[[[>M427014_AVA_
MAKNISRTAQMRVAIEEL

>L427D15_AVB_
MSGATSRTGNLRKEIEELVLT

>F83R906_GVB_
MAKIRANIPELLCAGVT

s004
5039.1
40403
0
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

Use sed -i to edit the file in place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.