lineon => to get one sentence per line
This commit is contained in:
parent
63a602b979
commit
124cbfd74e
1 changed files with 22 additions and 0 deletions
22
perl/lineon.pl
Executable file
22
perl/lineon.pl
Executable file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/perl -w
|
||||||
|
use v5.20;
|
||||||
|
|
||||||
|
sub usage {
|
||||||
|
say "usage : $0 [pattern [replacement]]";
|
||||||
|
}
|
||||||
|
|
||||||
|
do { usage ; exit 1} if @ARGV > 2;
|
||||||
|
do { usage ; exit 0} if @ARGV == 1 && $ARGV[0] =~ /-h/i;
|
||||||
|
|
||||||
|
my ($pattern, $repl) = @ARGV;
|
||||||
|
#say "pattern: $pattern, replacement: $repl";
|
||||||
|
|
||||||
|
@ARGV = ();
|
||||||
|
my $lines = '';
|
||||||
|
|
||||||
|
$lines .= $_ while (<>);
|
||||||
|
$lines =~ s/\n/ /g;
|
||||||
|
|
||||||
|
my @l = split /$pattern/, $lines;
|
||||||
|
map { $_ .= $repl } @l;
|
||||||
|
say for @l;
|
Loading…
Add table
Reference in a new issue