Post by Peter Cooper on July 13th, 2006

Ruby Command Line One Liners

Oneliners

Perl is particularly well known for its one-liners from the command prompt, but Ruby is pretty adept at it too. David P Thomas has put together a collection of about 100 Ruby one-liners in a single text file for us all to enjoy.

2 Responses to “Ruby Command Line One Liners”

  1. #1
    hgs Says:

    Or one could just use glark http://www.incava.org/projects/glark/ which is ruby grep with (optionally) highlighted output, ruby regexps, many features from gnu grep and the find command.

    glark '/foo.*bar.*baz/' file
    glark '/foo|bar|baz/' file
    glark -0 regexp file
    glark -0 --and=1 foo --and=1 bar baz file
    glark -0 'foo.*bar.*baz' file

    should do the above.

    For other one liners there is:
    http://wiki.rubygarden.org/Ruby/page/show/OneLiners

  2. #2
    Michael Says:

    None of those above examples SHOULD require "cat", should they? (Hearkening back to Randal Schwartz' "Useless use of 'cat'" awards days..."