#!/usr/bin/env ruby require 'trollop' require 'zipf' opts = Trollop::options do banner "select_from [--invert] -i < " 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 = {} f = ReadFile.new opts[:index] f.readlines_strip.each { |line| i = line.strip.to_i accept[i] = true } i=0 if opts[:from1] i = 1 end while line = STDIN.gets if accept[i] && !opts[:invert] STDOUT.write line elsif !accept[i] && opts[:invert] STDOUT.write line end i += 1 end