Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is the input:


and I need this output:



So I used a:

echo -e 'asdfZE3033141xycf\nasdfINSFRHxycf' | sed '/asdfZE3033141xycf/ s=xycf$=\n='

but I need this in GENERAL. So I need to sed every:


line in a textfile. I just can't put the "[0-9]" in sed. How can I do this?

share|improve this question
up vote 1 down vote accepted

Why do not modify your work a little bit:

echo -e 'asdfZE3033141xycf\nasdfINSFRHxycf' | sed -e 's/^\(asdfZE[0-9]\{7\}\)xycf$/\1\n/'
share|improve this answer

What's wrong with "[0-9]"? Why you can't put it in sed?

Use can simply use

sed '/asdfZE[0-9][0-9][0-9][0-9][0-9][0-9][0-9]xycf/s=xycf$=\n=' file

or even

sed '/asdfZE[0-9]\{7\}xycf/s=xycf$=\n=' file

sed support regex in search pattern.

share|improve this answer

Not sure what you mean.

What about:

sed 's/^\(asdfZE[0-9]\{7\}\)xycf$/\1\

? (backslash followed by a real newline character is the standard way to insert a newline character on the right hand side of the s command (as opposed to \n)).

share|improve this answer
I'm sorry, could you please decrypt RHS abbreviate? – rush Mar 13 '13 at 12:22
@rush. RHS == Right Hand Side. Now expanded. – Stéphane Chazelas Mar 13 '13 at 13:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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