How Perl one-liner for herding a group of sequences, out of its superset group, to be processed in a block of codes
The task fail done:
$ for i in {1..9} ;{ echo $i ;} |perl -pe 'my $s; if (/3/) { while(1) { $s .= $_; print $s; last if (/7/) } } '
to use Perl -pe
option do output of string lines of:
1
2
3
4567
8
9
CodePudding user response:
Use this Perl one-liner:
for i in `seq 9` ; do echo $i; done | \
perl -lne 'if ($_ == 3 .. $_ == 7) { push @a, $_; print @a if $_ == 7; next; } print;'
1
2
34567
8
9
The Perl one-liner uses these command line flags:
-e
: Tells Perl to look for code in-line, instead of in a file.
-n
: Loop over the input one line at a time, assigning it to $_
by default.
-l
: Strip the input line separator ("\n"
on *NIX by default) before executing the code in-line, and append it when printing.
SEE ALSO:
perldoc perlrun
: how to execute the Perl interpreter: command line switches