summaryrefslogtreecommitdiff
path: root/split_pipes
diff options
context:
space:
mode:
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
+