summaryrefslogtreecommitdiff
path: root/splitpipes
blob: b0c3c9c7ab57cd4474aafcc4bfa70870a7f73680 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env ruby

require 'trollop'


STDIN.set_encoding 'utf-8'
STDOUT.set_encoding 'utf-8'

def usage
  STDERR.write "splitpipes -f <n> < <input>\n"
  exit 1
end
usage if ARGV.size!=2

opts = Trollop::options do
  opt :field, "field", :type => :int
end

while line = STDIN.gets
  j = 1
  line.strip.split(' ||| ').each { |i|
    if j == opts[:field]
      puts i.strip
      break
    end
    j += 1
  }
end