How to convert .xls to .csv in Unix

1.3k views Asked by At

I have a text file (abc.txt) which will be having the file name along with the path which is to be converted to .csv. Below is the script I wrote:

 {while IFS= read -r f ; do
 filename="${f%.*}"
 ssconvert ${filename}.xls ${filename}.csv
done < abc.txt}

Problem is the file .xls file name having space in it. So the script is not working,says:

Unable to guess exporter to use for 'file:

1

There are 1 answers

9
l'L'l On BEST ANSWER

You should surround the following in double-quotes to prevent globbing and word splitting:

ssconvert "${filename}.xls" "${filename}.csv"

Also include a space between your curly-brackets and the next/previous object { ... }:

{ while IFS= read -r f ; do
      filename="${f%.*}"
      ssconvert "${filename}.xls" "${filename}.csv"
done < abc.txt ; }

Note: If you are still having issues with the "export type" error mentioned in the comments maybe try ssconvert "${filename}".xls "${filename}".csv as I'm not familiar with the exact syntax it requires. You can check your scripts easily with the online tool shellcheck.net.