# Word split with 2 columns

**URL:** <https://www.ruby-forum.com/t/word-split-with-2-columns/54973>\
**Category:** Ruby\
**Created:** [March 15, 2006, 6:18pm UTC](https://www.ruby-forum.com/t/word-split-with-2-columns/54973 "2006-03-15T18:18:14Z")\
**Posts on this page:** 2\
**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:** [March 15, 2006, 6:18pm UTC](https://www.ruby-forum.com/t/word-split-with-2-columns/54973/1 "2006-03-15T18:18:14Z")

</div>

Hi everyone!  
I need a little help. I have a script for ruby:

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 script should split two words with special parameter (from a plain  
text it makes xml source). That works so fine if I have ONLY two  
columns, but if I put several lines in the txt file beginning it dies.  
So, my only question is: how can I bring ruby that it should from line  
nr. X (i.e. 6 or 7) begin? And another question: can ruby after the  
conversion put in the file a line (ie. )?  
Thanks, regards:

Daniel  
removed\_email\_address@domain.invalid

---

<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:** [March 15, 2006, 7:01pm UTC](https://www.ruby-forum.com/t/word-split-with-2-columns/54973/2 "2006-03-15T19:01:28Z")

</div>

Dani wrote:

> File.open(outfile,‘w’) do |file|  
> file.write marked\_up\_lines.join  
> end
> 
> This script should split two words with special parameter (from a plain  
> text it makes xml source). That works so fine if I have ONLY two  
> columns, but if I put several lines in the txt file beginning it dies.  
> So, my only question is: how can I bring ruby that it should from line  
> nr. X (i.e. 6 or 7) begin?  
> …  
> start\_line = 6 #or 7, or whatever…  
> marked\_up\_lines = lines[start\_line…-1].map do |line|  
> …

> And another question: can ruby after the  
> conversion put in the file a line (ie. )?  
> File.open(outfile,‘w’) do |file|  
> file.write marked\_up\_lines.join  
> file.write ‘’  
> end

cheers
