#!/usr/bin/perl # print lines in a file between the pattern and the pattern # usage: fromto use strict; use warnings; use Getopt::Long; my $skip; my $help; my $result = GetOptions("skip|s" => \$skip, "help|h" =>); sub usage { print STDERR "Usage: fromto [options] []\n"; print STDERR "Options:\n"; print STDERR " -s Skip the lines matching the patterns\n"; print STDERR "Notes:\n"; print STDERR " Reads from stdin if no file name is supplied\n"; print STDERR " Patterns are in Perl compatible regex syntax\n"; } if (!$result) { usage; exit 2; } if ($help) { usage; exit 0; } my $from = shift @ARGV; my $to = shift @ARGV; my $started = 0; my $skipmarker = 0; LINE: while (<>) { if ($started) { if ($to && /$to/) { if (!$skipmarker) { print; } $started = 0; next LINE; } else { print; next LINE; } } if (!$from || /$from/) { $started = 1; if (!$skipmarker) { print; } next LINE; } }