Solved

vi replace " " with return

Posted on 2001-06-26
8
255 Views
Last Modified: 2010-04-21
I need to remove every space " " in a text file with a carrage return so that every word appears as a different line on the text.
0
Comment
Question by:Stoke
8 Comments
 

Expert Comment

by:vinayaca
ID: 6227116
try this command in VI editor (Command mode)

:s/" "/^M/g

0
 
LVL 5

Expert Comment

by:marecs
ID: 6227459
:%s/ /\n/g
0
 

Author Comment

by:Stoke
ID: 6227563
Neither option works
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 5

Expert Comment

by:marecs
ID: 6227609
What OS?

By not working do you mean nothing happened or the wrong thing happened?
0
 

Author Comment

by:Stoke
ID: 6227639
Red hat 7.1
:%s/ /\n/g returns ^@ instead of the spaces, so something happens.
0
 
LVL 5

Accepted Solution

by:
marecs earned 50 total points
ID: 6227892
This is cheating a bit, but it works. I think the problem is that vi would lose its sence of line numbers if it allowed something to be replaced by a newline. It worked on vim under Windows though!

:%!tr " " "\n"

It actually makes use of the external program tr
0
 

Author Comment

by:Stoke
ID: 6227993
Brilliant. That's exactly what I wanted.
0
 

Expert Comment

by:tomasino
ID: 8744280
it sounds like you were running gvim for windows if it displays ^@.  if you don't have the external program tr, you can still use the internal sed commands in vi on a windows machine by doing this:

:s/\ /\r/g

the \r is the newline character for PC.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

774 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question