File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes Xargs question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Xargs question" Watch "Xargs question" New topic
Author

Xargs question

Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2851
    
  11

I have a tool that does some processing on a file, and out the result in a specified output directory. So the normal syntax is like:
mytool -d ./output myfile.ext

I'd like to run the tool on a group of files and output the results into output in a hierarchy matching the source, so something like:
find . -name \*.ext | xargs mytool -d ???

I can't figure out how to do that. I want to take the dirname of each file and use that as the argument to the -d parameter. I've tried various permutations involving {}, exec, and ``, but so far I haven't hit the magic combination. If it matters, I'm running on Windows using Cygwin.
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1053
    
  10

The best I can do is -


Edit : Changed for the second time the way in which the result of the 'find' is used.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16058
    
  21

If it works, good enough.

Here's another approach:


This just displays the generated command. Remove the "echo" to actually run it. Tweak as needed for your actual needs - I didn't attempt to precisely replicate what you wanted.


Customer surveys are for companies who didn't pay proper attention to begin with.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2851
    
  11

Tim Holloway wrote:If it works, good enough.

Here's another approach:


This just displays the generated command. Remove the "echo" to actually run it. Tweak as needed for your actual needs - I didn't attempt to precisely replicate what you wanted.


Great, that worked! I had to alter `basename $F` to just plain $F though, probably because I described the problem wrong. Thanks to both of you for your help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Xargs question