# Split words with two columns

**URL:** <https://www.ruby-forum.com/t/split-words-with-two-columns/58098>\
**Category:** Ruby\
**Created:** [April 18, 2006, 1:55pm UTC](https://www.ruby-forum.com/t/split-words-with-two-columns/58098 "2006-04-18T13:55:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@dani](https://www.ruby-forum.com/u/dani)\
**Post date:** [April 18, 2006, 1:55pm UTC](https://www.ruby-forum.com/t/split-words-with-two-columns/58098/1 "2006-04-18T13:55:24Z")

</div>

Hi everyone, I need a little support. I have this script:

outfile = ARGV.shift

lines = ARGF.readlines  
marked\_up\_lines = lines.map do |line|  
words = line.split  
‘’ + words[1] + ‘’ + “\n”  
end

File.open(outfile,‘w’) do |file|  
file.write marked\_up\_lines.join  
end

This should split words in two columns to a HTML tag. But if I have more  
then two words in the columns it cut down from the thrid word.  
What should I add to see the other words? Or, does anyone have a better  
script?  
Regards,

Daniel

---

<div class="post-metadata">

**Author:** ![dani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@dani](https://www.ruby-forum.com/u/dani)\
**Post date:** [April 18, 2006, 2:04pm UTC](https://www.ruby-forum.com/t/split-words-with-two-columns/58098/2 "2006-04-18T14:04:45Z")

</div>

You could use shift and then join the rest:

“\<mezo eazon=”#{words.shift}"\>#{words.join(’ ')}\n"

---

<div class="post-metadata">

**Author:** ![dani](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@dani](https://www.ruby-forum.com/u/dani)\
**Post date:** [April 18, 2006, 2:54pm UTC](https://www.ruby-forum.com/t/split-words-with-two-columns/58098/3 "2006-04-18T14:54:29Z")

</div>

On 18/04/06, Farrel L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> You could use shift and then join the rest:

Even better, just don’t split them in the first place:

marked\_up\_lines = lines.map do |line|  
eazon, mezo = line.split($;, 2)  
“\<mezo eazon="#{eazon}"\>#{mezo}\n”  
end

Paul.
