From d946f0172e1c2524f539339a5c793609d26e3e74 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Mon, 27 Nov 2017 18:37:27 +0100 Subject: fix select-from --- select-from | 17 ++++++++++++----- 1 file 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 < " - 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 -- cgit v1.2.3