aspose file tools
The moose likes Linux / UNIX and the fly likes using exec in find, awk? xargs? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Reply Bookmark "using exec in find, awk? xargs?" Watch "using exec in find, awk? xargs?" New topic
Author

using exec in find, awk? xargs?

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 3688

I want to run the ImageMagick "convert" program on a bunch of files. The find command is the obvios way to find the files.

find . -name "*.tif" -print
works perfectly.

What I want to do is run the convert program, something like

convert foo.tif foo.png

So I want to get the name and add a new extension, .png

Any help or even hints will be greatly appreciated.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 9982

If you know that your files will all end in tiff, then you could just use sed:


(Untested, but it should work, unless you have spaces in your filenames, in which case that is a separate problem)


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 12513

If you're truly evilly-minded, use the "xargs" utility and do it as a one-liner. I'm not up to actually attempting this on the spot, but if would be something vaguely resembling this, I think:


The trickiest part is probably going to be the filename subsitution on the xargs command, but I believe that using double-quotes around the braces is the way it works.


One of the most odious afflictions that Business has inflicted on the modern English language is "pro-active". Most of the time it's simply redundantly used in place of the simple old word "active". And a good deal of the rest of the time it means "You're not overworked enough yet, so go out and find more!"
 
 
subject: using exec in find, awk? xargs?
 
Threads others viewed
Need Java program to convert SVG to PDF format
How can we know if JVM has been installed on a machine?
Running My First Java Application
A trouble of System class path
i changed a folder name and now my program wont run
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com