Robert Klemme wrote:
> Todd Breiholz wrote:
>> I'm just getting my feet wet with Ruby and would like some advice on
>> how you "old-timers" would write the following script using Ruby
>> idioms.
>>
>> The intent of the script is to parse a CSV file that contains 2
>> fields per row, sorted on the second field. There may be multiple
>> rows for field 2. I want to get a list of all of the unique values of
>> field2 that has more than 1 value for the 1st 6 characters of field
>> 1.
>
> There are two possible interpretations of what you state here:
>
> 1. You want all values for row2 that occur more than once.

Just remembered that the file is sorted.  Then this implementation of case
1 is even more efficient as it does not store values in mem and works on
arbitrary large files:

require 'csv'

last = nil
CSV::Reader.parse(ARGF) do |row|
  last, k = row[1], last
  puts k if last == k
end

Kind regards

    robert