Skip to content

Instantly share code, notes, and snippets.

@methane
Forked from sh2/head_tail.pl
Created March 5, 2013 05:23
Show Gist options
  • Save methane/5088227 to your computer and use it in GitHub Desktop.
Save methane/5088227 to your computer and use it in GitHub Desktop.
#!/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, '| tail') or die $!;
if (defined(my $line = <STDIN>)) {
print "==\n";
print $tail $line;
}
while (my $line = <STDIN>) {
print $tail $line;
}
close($tail);
}
#!/usr/bin/env python
from collections import deque
import sys
for _, L in zip(range(10), sys.stdin):
sys.stdout.write(L)
tail = deque(sys.stdin, maxlen=10)
if tail:
print "=="
sys.stdout.writelines(tail)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment