diff options
author | Patrick Simianer <p@simianer.de> | 2017-11-27 18:37:27 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2017-11-27 18:37:27 +0100 |
commit | d946f0172e1c2524f539339a5c793609d26e3e74 (patch) | |
tree | 5174f58219bb533057e82795fa880322918cbcc0 /select-from | |
parent | 4bf6ab567b2358122139130dc02932048a2882e8 (diff) |
fix select-from
Diffstat (limited to 'select-from')
-rwxr-xr-x | select-from | 17 |
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 |