Connecting Tech Pros Worldwide Help | Site Map

excel data manipulation through Ruby

Newbie
 
Join Date: Feb 2008
Posts: 1
#1: Feb 15 '08
Here's what I'd like to do

have a list of any number of words in excel in a column.

have another list of any number of words in another column

I want to take each word from List A and concatenate it with each word in list B.

So if list A had:

pumpkin
birds
hawks
seafood


and if list B had:

fast
scream
wow

the script would produce
pumpkin fast
pumpkin scream
pumpkin wow
birds fast
birds scream
birds wow
hawks fast
hawks scream
hawks wow
seafood fast
seafood scream
seafood wow

I don't need a GUI, just something I can execute from the command prompt. I know a little bid about ruby so I know this is just some basic array manipulation and concatenation...any takers?

Thanks,

J
Expert
 
Join Date: May 2007
Posts: 213
#2: Feb 15 '08

re: excel data manipulation through Ruby


You would want to do a loop within a loop. Loop through list A, and for each element in list A, loop through list B and concatenate.
Expand|Select|Wrap|Line Numbers
  1. list_a.each{|a| list_b.each{|b| puts a.to_s + b.to_s}}
Reply