#!/usr/bin/ruby # arguments: delimiter index ... # split each line at delimiter character and only display selected parts. displayed parts are separated by spaces. delimiter = Regexp.new Regexp.escape(ARGV[0]) + "+" indices = ARGV[1..-1].map &:to_i $stdin.each_line {|a| a = a.split delimiter b = indices.map {|i| a[i] || ""} puts b.join(" ").strip }