This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Basic sed question

Hi all,

Basic sed question:

This sed substitution works fine to replace a string of Ns with a Z:

cat test1 | sed -E "s/N{10}/Z/g"

But the reverse replaces a Z with the literal string "N{10}"

cat test2 | sed -e "s/Z/N{10}/g"

and returns something like this:

AAAAN{10}CCCCCC

I've tried to to this a variety of ways, but can't find anything that works.

Any advice will be appreciated.

fasta sed

How can I replace a "Z" with 10 Ns?

(Note: I can just type in 10 Ns in the sed command, but I'm trying to understand the syntax.)

as far as I know, there is no 'print x time operator' in sed.

You could use command substitution to insert a bash seq operation as long as the sed substitution was softquoted I think, but its a hack

1 answer

you can do with Perl:

$ echo AAAAZCCCC | perl -pe '$N="N"x10; s/Z/$N/'
AAAANNNNNNNNNNCCCC

Log in to answer this question.