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

vi \ ex : Substitute with newline?

Reply to Message Icon

Original Message
Name: caffiene
Date: September 22, 2004 at 08:02:40 Pacific
Subject: vi \ ex : Substitute with newline?
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


Report Offensive Message For Removal


Response Number 1
Name: Jim Boothe
Date: September 22, 2004 at 11:59:17 Pacific
Subject: vi \ ex : Substitute with newline?
Reply: (edit)

: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/[ ]*$


Report Offensive Follow Up For Removal

Response Number 2
Name: caffiene
Date: September 22, 2004 at 12:51:01 Pacific
Subject: vi \ ex : Substitute with newline?
Reply: (edit)

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.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: vi \ ex : Substitute with newline?

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge