From: Hal Fulton Date: 2006-01-05T04:03:37+09:00 Subject: Re: Searching a file for keywords? 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. Here's a first stab at it: str = `whatever_command` arr = str.split(" ") puts arr.grep(/hda[^0-9]/) Assuming you just want that word and not the whole line. Also assuming other things. Hal