This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 2841
    
  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: 1035
    
  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: 15961
    
  19

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: 2841
    
  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
 
Similar Threads
Cannot access the HelloWorldServlet
A newbie unix question, xargs
Unix scripting with Perforce commands - Need help
HELP.....HTTP Status 404 - /servlet/TestServlet is Not Availble
how the the same operation with "pipe"...