in reply to Re: Printing specific line numbers
in thread Printing specific line numbers
perl -MTie::File -ne 'BEGIN{tie(@f,"Tie::File",shift,mode=>0,autochomp +=>0) or die "tie failed $!"} print@f[$_..$_+2]'
Give the filename to read first, and any other filenames given will contain line numbers; if only one filename is given, numbers come from STDIN. For example:
$ echo 0 |perl -MTie::File -ne 'BEGIN{tie(@f,"Tie::File",shift,mode=>0 +,autochomp=>0) or die "tie failed $!"} print@f[$_..$_+2]' /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin $
|
|---|