• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Xargs question

 
Greg Charles
Sheriff
Posts: 2989
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greg Charles
Sheriff
Posts: 2989
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic