diff options
author | Patrick Simianer <p@simianer.de> | 2015-01-14 13:24:58 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2015-01-14 13:24:58 +0100 |
commit | a2f3a06467327165e28d90cdf03f82e3c4fef46e (patch) | |
tree | 815e185030628638b613cc23f16024275607f33f | |
parent | 77ca2f06c1f1ee9689138e1edf7d66e0214c231b (diff) |
select_from: invert
-rwxr-xr-x | select_from | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/select_from b/select_from index 14fbc9e..7ab40e7 100755 --- a/select_from +++ b/select_from @@ -1,7 +1,14 @@ #!/usr/bin/env ruby +require 'trollop' require 'zipf' +opts = Trollop::options do + banner "select_from [--invert] -i <file> < <line separated data>" + 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] @@ -11,7 +18,9 @@ f.readlines_strip.each { |line| i = 0 while line = STDIN.gets - if accept[i] + if accept[i] && !opts[:invert] + STDOUT.write line + elsif !accept[i] && opts[:invert] STDOUT.write line end i += 1 |