From 2b1d7f881c19c4d4b5afae194e02d3300c7675d0 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Tue, 5 Jul 2016 11:01:46 +0200 Subject: mv --- select-from | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 select-from (limited to 'select-from') diff --git a/select-from b/select-from new file mode 100755 index 0000000..7ab40e7 --- /dev/null +++ b/select-from @@ -0,0 +1,28 @@ +#!/usr/bin/env ruby + +require 'trollop' +require 'zipf' + +opts = Trollop::options do + banner "select_from [--invert] -i < " + 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 + -- cgit v1.2.3