# Irb output

**URL:** <https://www.ruby-forum.com/t/irb-output/64506>\
**Category:** Ruby\
**Created:** [August 9, 2006, 5:37pm UTC](https://www.ruby-forum.com/t/irb-output/64506 "2006-08-09T17:37:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![newyorkdolluk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/0ea827/32.png) [@newyorkdolluk](https://www.ruby-forum.com/u/newyorkdolluk)\
**Post date:** [August 9, 2006, 5:37pm UTC](https://www.ruby-forum.com/t/irb-output/64506/1 "2006-08-09T17:37:56Z")

</div>

hi,

i have a ruby/watir script that i evoke from irb containing the  
following lines:

ie\_attach = Watir::IE.attach(:url, /text/)  
ie\_attach.show\_links

this will attach to an open browser containing a webpage with ‘text’ in  
the url and then display all the html objects in that page.

can anyone advise on how i can redirect this output in the irb window  
into a file

thanks.

---

<div class="post-metadata">

**Author:** ![newyorkdolluk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/0ea827/32.png) [@newyorkdolluk](https://www.ruby-forum.com/u/newyorkdolluk)\
**Post date:** [August 9, 2006, 7:11pm UTC](https://www.ruby-forum.com/t/irb-output/64506/2 "2006-08-09T19:11:29Z")

</div>

newyorkdolluk wrote:

> hi,
> 
> i have a ruby/watir script that i evoke from irb containing the  
> following lines:
> 
> ie\_attach = Watir::IE.attach(:url, /text/)  
> ie\_attach.show\_links
> 
> this will attach to an open browser containing a webpage with ‘text’ in  
> the url and then display all the html objects in that page.
> 
> can anyone advise on how i can redirect this output in the irb window  
> into a file
> 
> thanks.

require ‘watir’  
include Watir

ie = IE.attach(:url, “[http://www.ruby-forum.com/topic/76597#new](http://www.ruby-forum.com/topic/76597#new)”)  
file = File.new(“links.txt”,“w+”)

ie.links.each {|link|  
file.puts(“#{link.innerText} - #{link.href}”) unless  
link.innerText.empty?  
}

file.close()

## Portion of output (some word wrapping may occur)

Ruby - [http://www.ruby-forum.com/forum/4](http://www.ruby-forum.com/forum/4)  
Forum List - [http://www.ruby-forum.com/](http://www.ruby-forum.com/)  
New Topic - [http://www.ruby-forum.com/topic/new?forum\_id=4](http://www.ruby-forum.com/topic/new?forum_id=4)  
Search - [Search results for '' - Ruby-Forum](http://www.ruby-forum.com/search)  
User settings - [http://www.ruby-forum.com/user/edit](http://www.ruby-forum.com/user/edit)  
User List - [http://www.ruby-forum.com/user/list](http://www.ruby-forum.com/user/list)  
Log Out [pkspence] - [http://www.ruby-forum.com/user/logout](http://www.ruby-forum.com/user/logout)  
irb output - [Irb output - Ruby - Ruby-Forum](http://www.ruby-forum.com/topic/76597#120103)  
Reply with quote -  
[http://www.ruby-forum.com/topic/76597?reply\_to=120103#postform](http://www.ruby-forum.com/topic/76597?reply_to=120103#postform)  
Enable email notification -  
[http://www.ruby-forum.com/topic/subscribe/76597](http://www.ruby-forum.com/topic/subscribe/76597)

---

<div class="post-metadata">

**Author:** ![newyorkdolluk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/0ea827/32.png) [@newyorkdolluk](https://www.ruby-forum.com/u/newyorkdolluk)\
**Post date:** [August 15, 2006, 2:12pm UTC](https://www.ruby-forum.com/t/irb-output/64506/3 "2006-08-15T14:12:14Z")

</div>

Thats great thanks. Can this be modified so that we pull out only the  
index names (first column of output - looks like an integer) for those  
lines that have the text ‘example’ say in them?
