1

I know how to do this in a text editor but it shuts my computer down because I have a large file. I have tab-separated data like this all on a single line:

XP_23947974 XM_23947974 HG12390 product=blahblah NP_23947975 XM_23947975 HG12391 product=blahblah2

And I want to insert a line break at every either XP or NP. So, as it is tab-separated, in the text editor I was just going to do

Find:(\D)P_
Replace:\n\1P_

Giving

XP_23947974 XM_23947974 HG12390 product=blahblah
NP_23947975 XM_23947975 HG12391 product=blahblah2

But I want to use sed (etc) to do that. help appreciated.

2
  • Have you googled the problem? Seems like it would be common a issue. Post some code if you are having issues with it.
    – kravits88
    Commented Mar 13, 2014 at 6:06
  • I googled it a lot. But maybe I didn't use the correct combination of keywords. I didn't understand the use of the pipe which the below answer helped with. Commented Mar 13, 2014 at 23:26

1 Answer 1

2

This should do the trick:

sed -e 's/\(XP\|NP\)/\n\1/g'

You can test this with:

echo 'XP_23947974 XM_23947974 HG12390 product=blahblah NP_23947975 XM_23947975 HG12391 product=blahblah2' | sed -e 's/\(XP\|NP\)/\n\1/g'
3
  • No problems, glad I could help :) Do i get an 'up' on my answer? Commented Mar 13, 2014 at 6:18
  • I don't have the "rep" to do that. I need 15. Is there another way? I'm a newb. Commented Mar 13, 2014 at 23:24
  • 1
    You can still mark it as the answer by clicking the tick next to Nick's answer.
    – kravits88
    Commented Mar 13, 2014 at 23:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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