On Mar 5, 2004, at 10:24 AM, gabriele renzi wrote:

> il Sat, 6 Mar 2004 03:15:08 +0900, "Thomas Luedeke"
> <tluedeke / excite.com> ha scritto::
>
>
> I'd say:
>
> open('filename').grep(/pattern/).split[4]

except that element number four is the fifth element. no, not the movie 
;)

   open('filename').grep(/pattern/).split[3]

Also, unless I misunderstand, I think there may be many many lines; and 
grep returns an array, which can't be split.

if you want to create a filter script, that filters stdin to stdout:

   STDIN.read.grep(/pattern/).each{|line| puts line.split[3]}

If, on the other hand, you want a script that you can call like this:

% myscript input_file output_file

then you will be needing to read up a little more in ruby, I think. But 
here's some code for an example:

   filtered_data = File.open("input_file") do |file|
     file.read.grep(/pattern/).map{|line| line.split[3]}.join "\n"
   end

   File.open("output_file") do |file|
     file.write filtered_data
   end

--Mark