Steve Starr wrote:
> I am trying to find out how to search a file and find certain key
> words then print them.
> 
> Example:
> 
> #!/usr/bin/ruby
> 
> system("cat /proc/partitions > drives.txt")
> 
> 
> Output:
>    8     0    1007616 sda
>    8     1    1007600 sda1
>    3     0   33027622 hda
>    3     1   14651248 hda1
>    3     2   14651280 hda2
>    3     3    3719047 hda3
> 
> Now i would just want to print the word hda to the screen.
> 
> Any help would be nice.
> Thanks

ruby -ne 'puts "hda" if /hda/' /proc/partitions

Or, if you just want to match the exact string

ruby -ne 'puts "hda" if /\bhda\b/' /proc/partitions

And if you want to print it once only

ruby -ne '$f ||= /hda/; END { puts "hda" if $f }' /proc/partitions

From within a script

ARGF.select {|l| /hda/ =~ l}.empty? or puts "hda"

HDA - err - HTH

Kind regards

    robert