-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrange
More file actions
executable file
·44 lines (38 loc) · 914 Bytes
/
range
File metadata and controls
executable file
·44 lines (38 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/perl
use strict;
use Getopt::Std;
my $usage = "range -k column (zero-based, required)\n".
" -g [lines match if they are geq than this number]\n".
" -l and leq than this one\n\n".
"Both -g and -l are optional.\n";
my $key = 0;
my $greater = 'null';
my $lesser = 'null';
my %para = ();
getopts('k:g:l:', \%para);
if (defined($para{'k'})) {
$key = $para{'k'};
} else {
print "$usage\n";
exit (-1);
}
if (defined($para{'g'})) {
$greater = $para{'g'};
}
if (defined($para{'l'})) {
$lesser = $para{'l'};
}
while (my $line = <STDIN>) {
my (@items) = split (/\s+/, $line);
if (defined ($items[$key])) {
if (($greater ne 'null') && ($items[$key] < $greater)) {
print "toss $line";
next;
}
if (($lesser ne 'null') && ($items[$key] > $lesser)) {
print "toss $line";
next;
}
print "OK $line";
}
}