From: James Edward Gray II Date: 2006-12-19T07:21:24+09:00 Subject: Re: Output unique values in CSV columns to a text file On Dec 18, 2006, at 4:04 PM, Drew Olson wrote: > What I want to do is read in a CSV file and produce an output which > lists the unique values from each column in the following format: > > Column: ColHeader1 > UniqueVal1 > UniqueVal2 > Column: ColHeader2 > UniqueVal1 > UniqueVal2 > ... Well, if it all fits in memory it's super easy using FCSV's Tables: #!/usr/bin/env ruby -w require "rubygems" require "faster_csv" table = FCSV.parse(DATA.read, :headers => true) table.by_col!.each do |header, col| puts "#{header}:" puts " #{col.uniq.join(', ')}" end __END__ nums,letters 1,a 2,b 2,b 3,c 3,c 3,c James Edward Gray II