bash - Linux shell script - find all files and run a command on each one of them -


i'm trying port windows batch file linux shell script (bash).

here part giving me headache:

for /r %%g in (*metadata*.xml) ( java -jar %saxon%\saxon9he.jar -o:%%~ng.csv "%%g" %workdir%\transformbqt.xsl) 

what find .xml file containing text metadata , running xslt transformation on each of these files. takes 3 arguments

  • -o output file (this .csv same name .xml)
  • next target file
  • final argument .xsl file

i thinking of using following:

find /results/ -type f -name "*metadata*.xml" -exec  java -jar $saxon/saxon9he.jar -o:??? {} $workdir/transformxmi.xsl 

but doesn't quite work don't know how make output file have same name .xml (with .csv extension)

any tips?

you process results find line line , transform <file>.xml <file>.csv:

find /results/ -type f -name "*metadata*.xml" | while read file; java -jar $saxon/saxon9h3.jar -o:${file%.xml}.csv $file $workdir/transform.xmi.xsl; done 

this simple approach fails in case file names have spaces in paths/names.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -