#!/usr/bin/perl =head1 NAME line - a program to display a specific line of a file with optional context =head1 SYNOPSIS B S<[ -[B>] ] B> [ B> ]> =head1 DESCRIPTION This program is a simple L script that will display a specific line of a file, with a switch to provide context in much the same fashion as L. The first (optional) argument is the number of lines of context. The second option is the line number. The third (optional) option is the file name. If a file name is not supplied or is "-", STDIN is read. =head1 AUTHOR Steven Pritchard > =head1 SEE ALSO perl(1), grep(1), head(1), tail(1) =head1 NOTES If you have any question about how this program works, read the source. It is shorter than this documentation. =cut sub usage { print STDERR "line [-[]] []\n"; exit 0; } $line=shift; if ($line=~/^-(-|\d*)$/) { $context=$1; $line=shift; } &usage() if (!defined($line)); $file=shift || "-"; open(FILE, "<$file"); while (($count<$line) && ($_=)) { $count++; if ((($count+$context)>=$line) && ($count<$line)) { push(@context, $_); } } print @context; print; while ($context && ($_=)) { $context--; print; }