Solved

vi replace " " with return

Posted on 2001-06-26
8
251 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
 
LVL 5

Expert Comment

by:marecs
ID: 6227609
What OS?

By not working do you mean nothing happened or the wrong thing happened?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now