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

S

Spendius

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
 
T

Tilman Bohn

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
 
R

Rogan Dawes

Spendius said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top