Skip to content

Instantly share code, notes, and snippets.

@sh2
Last active December 14, 2015 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sh2/5087373 to your computer and use it in GitHub Desktop.
Save sh2/5087373 to your computer and use it in GitHub Desktop.
head + tail command
#!/usr/bin/perl
use strict;
use warnings;
my $count = 0;
while (my $line = <STDIN>) {
print $line;
if (++$count >= 10) {
last;
}
}
if ($count >= 10) {
open(my $tail, '|-', qw/tail/) or die $!;
if (defined(my $line = <STDIN>)) {
print "==\n";
print $tail $line;
}
while (my $line = <STDIN>) {
print $tail $line;
}
close($tail);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment