" header an...">

Adding text to an existing first line using sed

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

>SRR018006
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGN
>SRR018006
ACCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

What I want to do is add text (for example, "foo" to the> header), get:

>SRR018006-foo
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGN
>SRR018006-foo
ACCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

Is there a way to do this using SED? Preferably, the inline modification of the source file.

+3
source share
2 answers

This will do what you are looking for.

sed -ie 's/^\(>.*\)/\1-foo/' file
+7
source

since, judging by the previous article, you can also use awk: here is an awk solution.

# awk '/^>/{print $0"-foo";next}1' file
>SRR018006-foo
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNGN
>SRR018006-foo
ACCCGCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

# awk '/^>/{print $0"-foo";next}1' file > temp
# mv temp file

if you insist on sed

# sed -e '/^>/s/$/-foo/' file
+3
source

Source: https://habr.com/ru/post/1719949/


All Articles