Computing.Net > Forums > Unix > vi \ ex : Substitute with newline?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

vi \ ex : Substitute with newline?

Reply to Message Icon

Name: caffiene
Date: September 22, 2004 at 08:02:40 Pacific
OS: Windows 2000 Pro SP3
CPU/Ram: P3 600Mhz/256MB
Comment:

Is there a way to use the substitute command in vi to insert carriage returns? I'm looking at a line of data like this:

DATA1 DATA2 DATA3 DATA4 DATA5 ... so on

I want to break up each DATA entry into separate lines, like so:

DATA1
DATA2
DATA3
DATA4
... so on

I was thinking I could substitute the spaces for carriage returns, but I do not know of a way to insert carriage returns with vi.

Thanks ahead of time,
Carl



Sponsored Link
Ads by Google

Response Number 1
Name: Jim Boothe
Date: September 22, 2004 at 11:59:17 Pacific
Reply:

:g/DATA/s/ [ ]*/CtrlVCtrlM/g

For all lines containing the string DATA, the above command will change each string of spaces to a newline character. The CtrlVCtrlM are two control characters in a row: Ctrl-V and Ctrl-M

That would include one or more spaces at the end of the line as well. If you do not want trailing spaces to be converted to a newline, first remove them with:

:g/DATA/s/[ ]*$


0

Response Number 2
Name: caffiene
Date: September 22, 2004 at 12:51:01 Pacific
Reply:

Thank you Jim! That works like a charm. I did not realize there were special characters like that that could be put into the substitute command.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: vi \ ex : Substitute with newline?

vi / ex : resume on pattern fail www.computing.net/answers/unix/vi-ex-resume-on-pattern-fail/5854.html

Editing a file without awk or sed www.computing.net/answers/unix/editing-a-file-without-awk-or-sed/5437.html

control J in vi www.computing.net/answers/unix/control-j-in-vi/5398.html