SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Grep Arguments

  1. #1
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Grep Arguments

    Hello
    I'm trying to use Ruby's grep function in a way similar to how I would use the grep command in Linux.

    For instance, normally I would use the following shell command to find a line in a file based on a key word, then print the following three lines.

    Code:
    cat filename | grep -A3 keyword
    How would I emulate this command in ruby? The Ruby API hasn't been very helpful in discussing the grep command.

    If not grep in Ruby, perhaps rak can do this?

    Thanks!

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,255
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    I imagine you could do it by writing your own code. But I think using Rak would be a lot easier.

    http://rak.rubyforge.org/
    -A NUM, --after-context=NUM
    Print NUM lines of trailing context after matching
    lines.

  3. #3
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Mittineague, I'll look into that!

    Cheers!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •