For example text file:
Speak friend and enter
using a Perl script to remove whitespace and replace with carriage-return
Speak friend and enter
For example text file:
Speak friend and enter
using a Perl script to remove whitespace and replace with carriage-return
Speak friend and enter
create a file test.pl:
open my $hfile, $ARGV[0] or die "Can't open $ARGV[0] for reading: $!";
while( my $line = <$hfile> )
{
$line =~ s/\s+/\n/g;
print $line;
}
close $hfile;
then run it like:
perl test.pl yourfile.txt
or, if you don't want to use a file, you can do it all from the command line like:
perl -p -e "s/\s+/\n/g" yourfile.txt
You can use sed
sed -e "s/[ ]/\n/g"
or anything that works with regular expressions
"s/[ ]/\n/g"
If you want inplace editing you can use the -i switch. Check out perlrun to see how it's done, but, basically:
perl -p -i.bak -e 's/\s+/\n/g'
#!/usr/bin/perl -l
use strict;
use warnings;
print join "\n", split while <>;