Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 18 lines (14 sloc) 411 Bytes
#!/usr/bin/env ruby
#
# Usage: select-columns INTEGER # array index
# Usage: select-columns INTEGER..INTEGER # index range
#
# Copies the specified columns from STDIN to STDOUT.
#
# Written in 2010 by Suraj N. Kurapati <https://github.com/sunaku>
slices = ARGV.map {|a| eval a }
while input = STDIN.gets
src = input.split(/\s+/)
dst = slices.map {|s| src[s] }.flatten
puts dst.join(' ')
end