blob: 7ab40e7cd607e99e3987953b6526596d07c8f869 (
plain)
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
|
#!/usr/bin/env ruby
require 'trollop'
require 'zipf'
opts = Trollop::options do
banner "select_from [--invert] -i <file> < <line separated data>"
opt :index, "Line numbers to output.", :required => true
opt :invert, "Invert selection.", :type => :bool, :short => '-j', :default => false
end
accept = {}
f = ReadFile.new ARGV[0]
f.readlines_strip.each { |line|
accept[line.strip.to_i] = true
}
i = 0
while line = STDIN.gets
if accept[i] && !opts[:invert]
STDOUT.write line
elsif !accept[i] && opts[:invert]
STDOUT.write line
end
i += 1
end
|