Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using basename to name output file in java

I have a recursive structure of directories containing some foo files that I want to convert to bar files using a XSLT 1.0 stylesheet. I have:

dir
|-- subdir
|   |-- file1.foo
|   |-- file2.foo
|   |-- file3.foo

And I want to obtain:

dir
|-- subdir
|   |-- file1.foo
|   |-- file1.bar
|   |-- file2.foo
|   |-- file2.bar
|   |-- file3.foo
|   |-- file3.bar

To capture the basename of files without the extension, I have tried:

$ find . -type f -exec java -jar C:/saxon6-5-5/saxon.jar -o $(basename {} .foo).bar {} stylesheet.xsl \;

and

$ find . -type f -exec java -jar C:/saxon6-5-5/saxon.jar -o `basename {} .foo`.bar {} stylesheet.xsl \;

Both with identical result:

dir
|-- subdir
|   |-- file1.foo
|   |-- file1.foo.bar
|   |-- file2.foo
|   |-- file2.foo.bar
|   |-- file3.foo
|   |-- file3.foo.bar

It seems the basename command is not working. What can I be doing wrong?

like image 819
msoutopico Avatar asked Dec 19 '25 11:12

msoutopico


1 Answers

Here's a zsh approach, since it's tagged it as such.

for f in **/*.foo(.); print -- java ... -o $f:r.bar $f

Remove the print -- when you're satisfied that it looks good.

The (.) says files only. The :r says remove the .foo extension. It's helpful to remember the path manipulators as "erth" for extension/remove/tail/head.

There's also zmv with the -p option to call your java command.

like image 55
Micah Elliott Avatar answered Dec 21 '25 02:12

Micah Elliott



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!