# Printing from a file - beginner

**URL:** <https://www.ruby-forum.com/t/printing-from-a-file-beginner/122078>\
**Category:** Ruby\
**Created:** [December 4, 2007, 12:51pm UTC](https://www.ruby-forum.com/t/printing-from-a-file-beginner/122078 "2007-12-04T12:51:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d9b06d/32.png) [@johnsmith](https://www.ruby-forum.com/u/johnsmith)\
**Post date:** [December 4, 2007, 12:51pm UTC](https://www.ruby-forum.com/t/printing-from-a-file-beginner/122078/1 "2007-12-04T12:51:51Z")

</div>

hi there

im new to ruby and ive got a bit of a problem

basically i have a text file and i want my ruby class to perform a  
regular expression to count the lines with a Tag in the text file

if anyone could offer any help or psuedo code id be very appreciative

my code is below  
many thanks

text file:

Tag: ref1  
Type: Book  
Author: Little, S R

Tag: ref2  
Type: Journal  
Author: Smith, J

ruby code:

# 

require ‘getoptlong’

opts = GetoptLong.new(  
[’–style’, ‘-n’, GetoptLong::NO\_ARGUMENT],  
[’–database’, ‘-i’, GetoptLong::REQUIRED\_ARGUMENT]  
)  
opts.each do |opt, arg|  
case opt  
when ‘–style’  
require arg  
when ‘–database’  
end  
end

# 

# 

# 

# process options

# 

# 

# 

```
 File.open('reference.txt').each do |line|

```

# puts line

```
 Regexp.new
 end

```

# 

#

---

<div class="post-metadata">

**Author:** ![johnsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d9b06d/32.png) [@johnsmith](https://www.ruby-forum.com/u/johnsmith)\
**Post date:** [December 4, 2007, 1:31pm UTC](https://www.ruby-forum.com/t/printing-from-a-file-beginner/122078/2 "2007-12-04T13:31:00Z")

</div>

On Tue, 4 Dec 2007 06:51:49 -0500  
Johnathan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> hi there
> 
> im new to ruby and ive got a bit of a problem

new to this myself so take that into consideration 😉

> # 
> 
> ```
> when '--database'
> end
> 
> ```
> 
> end
> 
> # 
> 
> # 
> 
> # 
> 
> # process options
> 
> # 
> 
> # 
> 
> #

count = 0 (not sure I need that?)

> ```
> File.open('reference.txt').each do |line|
> 
> ```
> 
> # puts line
> 
> ```
> Regexp.new
> 
> ```

count += 1 if line =~ /^Tag:\s/  
(not sure if I need to escape the ‘:’ ie ‘:’)

> ```
> end
> 
> ```
> 
> # 
> 
> #

cheers,
