summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xselect-from17
1 files changed, 12 insertions, 5 deletions
diff --git a/select-from b/select-from
index 7ab40e7..98e4ff2 100755
--- a/select-from
+++ b/select-from
@@ -5,18 +5,25 @@ require 'zipf'
opts = Trollop::options do
banner "select_from [--invert] -i <file> < <line separated data>"
- opt :index, "Line numbers to output.", :required => true
+ opt :index, "Line numbers to output.", :type => :string, :short => '-i', :required => true
opt :invert, "Invert selection.", :type => :bool, :short => '-j', :default => false
+ opt :from1, "Index starting from 1.", :type => :bool, :short => '-k', :default => false
end
-accept = {}
+puts opts
-f = ReadFile.new ARGV[0]
+accept = {}
+f = ReadFile.new opts[:index]
f.readlines_strip.each { |line|
- accept[line.strip.to_i] = true
+ i = line.strip.to_i
+
+ accept[i] = true
}
-i = 0
+i=0
+if opts[:from1]
+ i = 1
+end
while line = STDIN.gets
if accept[i] && !opts[:invert]
STDOUT.write line