Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Implementing unix "grep" command in java

Reply
Thread Tools

Implementing unix "grep" command in java

 
 
nospam
Guest
Posts: n/a
 
      04-15-2005
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
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      04-15-2005


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.

--
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
 
Roland
Guest
Posts: n/a
 
      04-15-2005
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_/ /__/
/ \ /_/ / \
 
Reply With Quote
 
HK
Guest
Posts: n/a
 
      04-15-2005
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/wha...rams/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.

 
Reply With Quote
 
marcocast marcocast is offline
Junior Member
Join Date: Jul 2012
Posts: 1
 
      07-05-2012
you can have a look at grep4j http://code.google.com/p/grep4j/
 
Reply With Quote
 
winey winey is offline
Junior Member
Join Date: Jul 2013
Posts: 1
 
      07-03-2013
Unix4j also implements a grep command, see unix4j.org
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to debug java in unix command line William Shieh Java 3 05-15-2009 04:45 AM
Implementing Unix fmt ( ) function tempsl C Programming 0 11-16-2005 08:29 PM
Run Unix shell command $ parse command line arguments in python rkoida@yahoo.com Python 4 04-23-2005 04:42 AM
java command containing classpath in quotes on unix Nishi Bhonsle Java 8 01-05-2004 05:59 PM
Help on implementing COM on unix mshetty C++ 3 10-28-2003 06:18 PM



Advertisments