This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
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: 2956
    
  12

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
Bartender

Joined: Aug 27, 2012
Posts: 1166
    
  17

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: 17161
    
  27

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.


An IDE is no substitute for an Intelligent Developer.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2956
    
  12

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
 
jQuery in Action, 3rd edition