Maintain filename after converting

Have directory with lots of csv file, and want to convert them to xls.

/opt/report1.csv
/opt/report2.csv
/opt/checklist.csv

...

Here is my command:

tr '|' '\t' <report1.csv | ssconvert fd://0 report1.xls

How can modify this command to maintain all original file name after convert.
Like this:

report1.csv > report1.xls
report2.csv > report2.xls
checklist.csv > checklist.xls

Thanks,

You will put those command in a shell script using $1 for passing parameter as a file name, and using basename utility to get the filename without the extension.

E.g. create a file myconvert.sh, with something in the line as :

#!/bin/bash
tr '|' '\t' < "$1" | ssconvert fd://0 $(basename "$1" .csv).xls

And run it in working directory as to create a report.xls out of report.csv preserving original filename and changing extension :

./myconvert.sh report.csv 

There are other ways, of course, but please specify your shell and operating system in your future requests so we can help better !

Hope the helps.
Regards
Peasant.

2 Likes