Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using sed or VIM to replace space with new line

Tags:

linux

vi

unix

sed

I have the following data.

1455931_at Chrna3 1420468_at Asb17 1445520_at −−− 1436717_x_at Hbb−y 1431788_at Fabp12 1458975_at −−−

With sed or VIM editor how can I change it to

1455931_at Chrna3 
1420468_at Asb17 
1445520_at −−− 
1436717_x_at Hbb−y 
1431788_at Fabp12 
1458975_at −−−

So all the word that has _at will be the first of every line. Every line consist of pairwise _at and gene terms.

like image 495
pdubois Avatar asked Dec 04 '22 08:12

pdubois


1 Answers

In Vim, I would do this:

:%s/ /^M/g
:g/_at/j

Where the ^M is typed by pressing control-V (control-Q on Windows) followed by the Enter/Return key.

This assumes single spaces between tokens; as @Floris suggests, you can use s/ \+/^M/g to turn multiple consecutive spaces into a single newline. Or you could use s/\v\s+/^M/g to do the same thing with any consecutive whitespace including tabs as well as literal space characters.

like image 111
Mark Reed Avatar answered Dec 08 '22 16:12

Mark Reed