summaryrefslogtreecommitdiff
path: root/split-pipes
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2016-07-05 11:01:46 +0200
committerPatrick Simianer <p@simianer.de>2016-07-05 11:01:46 +0200
commit2b1d7f881c19c4d4b5afae194e02d3300c7675d0 (patch)
tree5a06ee7de98640a39244b57bb369697176b44ebf /split-pipes
parent69949dda35c3ea21d8e926e5f0a596a0a0f61c6a (diff)
mv
Diffstat (limited to 'split-pipes')
-rwxr-xr-xsplit-pipes51
1 files changed, 51 insertions, 0 deletions
diff --git a/split-pipes b/split-pipes
new file mode 100755
index 0000000..ce8f018
--- /dev/null
+++ b/split-pipes
@@ -0,0 +1,51 @@
+#!/usr/bin/env ruby
+
+require 'trollop'
+
+STDIN.set_encoding 'utf-8'
+STDOUT.set_encoding 'utf-8'
+
+conf = Trollop::options do
+ banner "splitpipes -f <n> < <input>"
+ opt :field, "field", :type => :int, :required => true
+ opt :to, "to", :type => :int, :default => nil
+end
+
+
+a = []
+range = false
+if conf[:to]
+ range = true
+end
+
+if range
+ if conf[:field] >= conf[:to]
+ STDERR.write "field >= to, exiting\n"
+ exit
+ end
+end
+
+if conf[:field]<=0 || (range && conf[:to]<=0)
+ STDERR.write "field or to <= 0, exiting"
+ exit
+end
+
+while line = STDIN.gets
+ j = 1
+ line.strip.split(' ||| ').each { |i|
+ if range && (conf[:field]..conf[:to]).include?(j)
+ a << i.strip
+ elsif j == conf[:field]
+ puts i.strip
+ break
+ end
+ j += 1
+ }
+ if range
+ puts "#{a.join " ||| "}\n"
+ end
+ a.clear
+end
+
+
+