File: extractlines.pl

package info (click to toggle)
igerman98 20161207-16
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,276 kB
  • sloc: perl: 925; makefile: 478; sh: 472; sed: 46
file content (19 lines) | stat: -rwxr-xr-x 524 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/perl
#
# Björn Jacke <bjoern@j3e.de>
#
# this script takes a sorted list of line numbers in a file as first argument
# and a file to extract this linenumbers from as second argument.

open(LINEFILE, "< $ARGV[0]") or die "Can't open lines file $ARGV[1]: $!\n";
open(GREPFILE, "< $ARGV[1]") or die "Can't open to-grep file $ARGV[2]: $!\n";

my $linecounter=0;
my $next_line=0;
while (<LINEFILE>) {
	$next_line=$_;
	while (<GREPFILE>) {
		$linecounter++;
		print "$_" and last if ($linecounter == $next_line);
	}
}