Unix commands implemented ? (grep, wc, cat...)

Discussion in 'Java' started by Spendius, Dec 11, 2004.

  1. Spendius

    Spendius Guest

    Hi,
    Maybe someone has written something that would allow to do
    things resembling this:
    > Stuff file = new Stuff("./readme.txt");
    > String[] result = file.uxCmd("grep -i hello");

    or
    > Vector result = file.uxCmd("grep -i hello");

    or
    > String[]/Vector result = file.grep("-i hello").pipe().wc("-l");

    or whatever...
    You see what I mean ?, tool classes that would permit to handle
    or run unix instructions the way you do it at the command prompt...

    Has anybody ever thought of that kind of stuff ?

    Thanks in advance...
    Regards,
    Spendius
    Spendius, Dec 11, 2004
    #1
    1. Advertising

  2. Spendius

    Tilman Bohn Guest

    On Sat, 11 Dec 2004 05:46:41 -0800, Spendius wrote:

    [...]
    >> String[]/Vector result = file.grep("-i hello").pipe().wc("-l");

    > or whatever...
    > You see what I mean ?, tool classes that would permit to handle
    > or run unix instructions the way you do it at the command prompt...
    >
    > Has anybody ever thought of that kind of stuff ?


    I'm not aware of any general project implementing all classic
    nix utilities. Some of them would be pretty large projects, like
    sed or awk, which I don't think anyone has done in java. However,
    at least for grep there is a (possibly not quite) complete java
    implementation of GNU grep in the gnu.regexp.util package:

    http://www.cacas.org/java/gnu/regexp/

    That might also give you some sed and awk functionality according
    to the description, but I suspect by syntax they only mean the regexp
    syntax, not the complete sed or awk language syntax.

    For simpler things like wc, there are always implementations
    floating around. I guess most search engines would be happy to dig
    them up for you.

    Cheers, Tilman

    --
    `Boy, life takes a long time to live...' -- Steven Wright
    Tilman Bohn, Dec 11, 2004
    #2
    1. Advertising

  3. Spendius

    Rogan Dawes Guest

    Spendius wrote:
    > Hi,
    > Maybe someone has written something that would allow to do
    > things resembling this:
    >
    >>Stuff file = new Stuff("./readme.txt");
    >>String[] result = file.uxCmd("grep -i hello");

    >
    > or
    >
    >>Vector result = file.uxCmd("grep -i hello");

    >
    > or
    >
    >>String[]/Vector result = file.grep("-i hello").pipe().wc("-l");

    >
    > or whatever...
    > You see what I mean ?, tool classes that would permit to handle
    > or run unix instructions the way you do it at the command prompt...
    >
    > Has anybody ever thought of that kind of stuff ?
    >
    > Thanks in advance...
    > Regards,
    > Spendius


    Interesting concept.

    As I see it, these would all be implemented as subclasses of
    FilterInputStream, in order to maintain the chainability.

    InputStream is = new GrepInputStream(System.in, "regex", options);
    InputStream is = new WordCountInputStream(is, LINE);

    InputStream is = new SedInputStream(is, "sed program");
    BufferedInputStream bis = new BufferedInputStream(is);

    while ((line=bis.readLine()) != null) {
    // do something with line
    }

    In many cases, though, this kind of paradigm is inappropriate for a
    compiled program. It is usually more powerful to have specified classes
    that implement the desired functionality.

    e.g. WordCountInputStream would be more interesting as:

    WordCounter wc = new WordCounter(is);
    int words = wc.getWords();
    int lines = wc.getLines();
    int characters = wc.getCharacters();

    etc, etc, etc

    Regards,

    Rogan
    --
    Rogan Dawes

    *ALL* messages to will be dropped, and added
    to my blacklist. Please respond to "nntp AT dawes DOT za DOT net"
    Rogan Dawes, Dec 13, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Al Belden

    perl vs Unix grep

    Al Belden, Jul 3, 2004, in forum: Perl
    Replies:
    1
    Views:
    5,167
    Giridhar Nandigam
    Jul 7, 2004
  2. nospam
    Replies:
    5
    Views:
    14,640
    winey
    Jul 3, 2013
  3. Ben Pfaff

    Re: man pages for C commands (GCC commands)

    Ben Pfaff, Jun 24, 2003, in forum: C Programming
    Replies:
    4
    Views:
    3,946
    Thomas Stegen
    Jun 28, 2003
  4. Tim Stanka
    Replies:
    1
    Views:
    784
    Jeff Epler
    Aug 2, 2004
  5. Al Belden

    perl vs Unix grep

    Al Belden, Jul 3, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    180
Loading...

Share This Page