On Mar 15, 2006, at 2:23 PM, Geoff wrote:

> Now what I want to do is check for blanks and when I find one I  
> want to
> take the info from the entry directly above and fill down the column
> until the next blank. Using the above example, I want the following
> output:
>
> "BegDoc","EndDoc","New"
> "Doc1BegDoc","Doc1EndDoc","Test1"
> "Doc2BegDoc","Doc2EndDoc","Test1"
> "Doc3BegDoc","Doc3EndDoc","Test2"
> "Doc4BegDoc","Doc4EndDoc","Test2"
> "Doc5BegDoc","Doc5EndDoc","New"
>
> Any help is greatly appreciated!

See if this gives you some ideas:

Neo:~/Desktop$ ls
csv_filldown.rb data.csv
Neo:~/Desktop$ cat data.csv
"BegDoc","EndDoc","New"
"Doc1BegDoc","Doc1EndDoc","Test1"
"Doc2BegDoc","Doc2EndDoc",""
"Doc3BegDoc","Doc3EndDoc","Test2"
"Doc4BegDoc","Doc4EndDoc",""
"Doc5BegDoc","Doc5EndDoc","New"
Neo:~/Desktop$ cat csv_filldown.rb
#!/usr/local/bin/ruby -w

require "csv"

last = ""

CSV.foreach(ARGV.shift) do |row|
   if row[-1].empty?
     row[-1] = last
   else
     last = row[-1]
   end

   p row
end

__END__
Neo:~/Desktop$ ruby csv_filldown.rb data.csv
["BegDoc", "EndDoc", "New"]
["Doc1BegDoc", "Doc1EndDoc", "Test1"]
["Doc2BegDoc", "Doc2EndDoc", "Test1"]
["Doc3BegDoc", "Doc3EndDoc", "Test2"]
["Doc4BegDoc", "Doc4EndDoc", "Test2"]
["Doc5BegDoc", "Doc5EndDoc", "New"]

James Edward Gray II