# Re: add to words syntaxes

**URL:** <https://www.ruby-forum.com/t/re-add-to-words-syntaxes/55015>\
**Category:** Ruby\
**Created:** [March 16, 2006, 9:28am UTC](https://www.ruby-forum.com/t/re-add-to-words-syntaxes/55015 "2006-03-16T09:28:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 16, 2006, 9:28am UTC](https://www.ruby-forum.com/t/re-add-to-words-syntaxes/55015/1 "2006-03-16T09:28:50Z")

</div>

* * *

* * *

datafile=“kest\_kft.txt” # insert correct name here  
text=IO.readlines(datafile) # read lines into Array

output\_file=“my\_nicely\_arranged\_text\_file.txt” # insert correct name  
here

class String  
def do\_first\_script  
# insert tags here  
return result  
end  
def do\_second\_script  
#insert tags here  
return result  
end  
end

f=File.new(output\_file,“w”)

# first alternative

# assuming that you’ll always have the same one/two-column

# structure

text.each\_with\_index{|x,i|  
if i\<5  
f.puts x.do\_first\_script  
else  
f.puts x.do\_second\_script  
end  
}

# second alternative (recommended)

# use regexps -

# assuming that you separate columns by tabs - and use tabs

# for nothing else than separating columns

text.each{|x|  
if x=~/\t/  
f.puts x.do\_first\_script  
else  
f.puts x.do\_second\_script  
end  
}

f.close
