Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appending Text To the Existing First Line with Sed

I have a data that looks like this (FASTA format). Note that in comes with block of 2 ">" header and the sequence.

>SRR018006
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGN
>SRR018006
ACCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

What I want to do is to append a text (e.g. "foo" in the > header) yielding:

>SRR018006-foo
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGN
>SRR018006-foo
ACCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

Is there a way to do that using SED? Preferably inline modifying the original file.

like image 542
neversaint Avatar asked Dec 17 '25 14:12

neversaint


1 Answers

This will do what you're looking for.

sed -ie 's/^\(>.*\)/\1-foo/' file
like image 56
EmFi Avatar answered Dec 19 '25 06:12

EmFi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!