Implementing unix "grep" command in java

Discussion in 'Java' started by nospam, Apr 15, 2005.

  1. nospam

    nospam Guest

    Hi..All,

    I have a request from my user to list of the files from the folders
    which has got the string he is searching for. How do I implement the
    unix command grep in JAVA. or are there any methods/interfaces in java
    that can scan file(s) in a given folder & do the same functionality?

    Regards,

    P
    nospam, Apr 15, 2005
    #1
    1. Advertising

  2. nospam

    Eric Sosman Guest

    nospam wrote:
    > Hi..All,
    >
    > I have a request from my user to list of the files from the folders
    > which has got the string he is searching for. How do I implement the
    > unix command grep in JAVA. or are there any methods/interfaces in java
    > that can scan file(s) in a given folder & do the same functionality?


    You have the machinery of java.io.File to locate the
    files in a directory, and other machinery in java.io to
    open them and read their contents. The java.util.regex
    package provides classes and methods that should be helpful
    in detecting the presence of the desired strings -- or if
    they're really just strings and not regular expressions,
    you might simply use the indexOf(String) method of String.

    --
    Eric Sosman, Apr 15, 2005
    #2
    1. Advertising

  3. nospam

    Roland Guest

    On 15-4-2005 17:33, nospam wrote:
    > Hi..All,
    >
    > I have a request from my user to list of the files from the folders
    > which has got the string he is searching for. How do I implement the
    > unix command grep in JAVA. or are there any methods/interfaces in java
    > that can scan file(s) in a given folder & do the same functionality?
    >
    > Regards,
    >
    > P

    Grep.java at
    <http://java.sun.com/j2se/1.5.0/docs/guide/nio/example/index.html>
    Don't know how it compares to Unix' grep.
    --
    Regards,

    Roland de Ruiter
    ___ ___
    /__/ w_/ /__/
    / \ /_/ / \
    Roland, Apr 15, 2005
    #3
  4. nospam

    HK Guest

    nospam wrote:
    > I have a request from my user to list of the files from the

    folders
    > which has got the string he is searching for. How do I implement the
    > unix command grep in JAVA. or are there any methods/interfaces in

    java
    > that can scan file(s) in a given folder & do the same functionality?


    How about:

    http://www.ebi.ac.uk/Rebholz-srv/whatizit/monq-doc/monq/programs/Grep.html

    It has a main() to run it from the command line,
    but all the functionality is encapsulated in
    a class too. The concept of `line' is, however,
    replaced by the concept of `region of interest',
    which makes it a nice tool for XML grepping.

    Harald.
    HK, Apr 15, 2005
    #4
  5. nospam

    marcocast

    Joined:
    Jul 4, 2012
    Messages:
    1
    marcocast, Jul 5, 2012
    #5
  6. nospam

    winey

    Joined:
    Jul 3, 2013
    Messages:
    1
    Unix4j also implements a grep command, see unix4j.org
    winey, Jul 3, 2013
    #6
    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,188
    Giridhar Nandigam
    Jul 7, 2004
  2. Spendius
    Replies:
    2
    Views:
    2,962
    Rogan Dawes
    Dec 13, 2004
  3. Replies:
    4
    Views:
    1,708
    Terry Hancock
    Apr 23, 2005
  4. Jul

    issue with grep command

    Jul, Sep 3, 2009, in forum: Python
    Replies:
    2
    Views:
    236
    Rhodri James
    Sep 3, 2009
  5. Al Belden

    perl vs Unix grep

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

Share This Page