Solved

vi replace " " with return

Posted on 2001-06-26
8
261 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix, date minus 1, 2 or 3 days (last working day) 11 68
reinstall 1 84
Wrap Oraccle SQL*Plus executable Command 4 95
How to make a Bash alias that takes parameters 5 72
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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.

839 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