summaryrefslogtreecommitdiff
path: root/split_pipes
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2015-01-15 09:33:45 +0100
committerPatrick Simianer <p@simianer.de>2015-01-15 09:33:45 +0100
commit5654c8d55b8fefa6956fd9285ee5cf2b8084a4bf (patch)
treec070ff561dcc65c1959f8e4dcecf2d8e17ddf40b /split_pipes
parenta2f3a06467327165e28d90cdf03f82e3c4fef46e (diff)
split_pipes: to param
Diffstat (limited to 'split_pipes')
-rwxr-xr-xsplit_pipes30
1 files changed, 28 insertions, 2 deletions
diff --git a/split_pipes b/split_pipes
index eeba69b..dd93d92 100755
--- a/split_pipes
+++ b/split_pipes
@@ -7,13 +7,35 @@ STDOUT.set_encoding 'utf-8'
cfg = Trollop::options do
banner "splitpipes -f <n> < <input>"
- opt :field, "field", :type => :int
+ opt :field, "field", :type => :int, :required => true
+ opt :to, "to", :type => :int, :default => nil
+end
+
+
+a = []
+range = false
+if cfg[:to]
+ range = true
+end
+
+if range
+ if cfg[:field] >= cfg[:to]
+ STDERR.write "field >= to, exiting\n"
+ exit
+ end
+end
+
+if cfg[:field]<=0 || (range && cfg[:to]<=0)
+ STDERR.write "field or to <= 0, exiting"
+ exit
end
while line = STDIN.gets
j = 1
line.strip.split(' ||| ').each { |i|
- if j == cfg[:field]
+ if range && (cfg[:field]..cfg[:to]).include?(j)
+ a << i.strip
+ elsif j == cfg[:field]
puts i.strip
break
end
@@ -21,3 +43,7 @@ while line = STDIN.gets
}
end
+if cfg[:to]
+ puts a.join " ||| "
+end
+