Rob
Eric
>> Something like:
>> tr "[:space:]" "\n" < somefile.txt > somefile.out
>> should do the trick
tr often doesn't like special characters, instead use the octal value
tr ' ' '\012' <input >output
or with tr:
tr ' ' '\n' <yourfile >newfile
or with perl:
open(FILE, "yourfilename");
open(NFILE, "newfilename");
while (<FILE>){
$_ =~ s/\s+/\n/g;
print NFILE $_;
}
close(FILE);
close(NFILE);
Robert G. Jacobs wrote:
> How can I use sed to replace all the spaces in a file with newlines? A
or with tr:
tr ' ' '\n' <yourfile >newfile
or with perl:
open(FILE, "yourfilename");
open(NFILE, "newfilename");
while (<FILE>){
$_ =~ s/\s+/\n/g;
print NFILE $_;
}
close(FILE);
close(NFILE);
=================
Fly Like An Eagle
=================
If you use classic vi (not vim) you might need to do it this way:
Q
s/ /\
/g
vi
The Q command puts you in ex mode; you cet a colon prompt. You can then
issue the s command replacing space with new line. Yhe new line must be
escaped with a backslash. Type vi to get back to vi mode.
Villy
Sajjad
SteveLiu (khon...@nease.net) wrote:
: In editor like vi,
> In vi, I always escape the Control-M by typing in Control-V (NUL)
> character beforehand. Else it does not work (at least for me). The other
> solutions look allright.
>
> Sajjad
>
> SteveLiu (khon...@nease.net) wrote:
> : In editor like vi,
> : use :
> : :1,$s/ /^M/g
>
> : or with tr:
>
> : tr ' ' '\n' <yourfile >newfile
>
Or in vi:
:%!tr ' ' '\n'
Sorry, just had to get that one in ;-)