2

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:

pnuts
  • 58,317
  • 11
  • 87
  • 139
Midhun
  • 331
  • 2
  • 5
  • 15
  • the question is terse in that you've not given details on how the filenames are arranged in the text file abc.txt. To be specific, what is the record separator? – sjsam Mar 14 '17 at 05:17

1 Answers1

1

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.

l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • @I'L'I, i am getting An output file name or an explicit export type is required error. – Midhun Mar 14 '17 at 05:16
  • @Midhun, Check the updated example and let me know if that works. You can also try it like `"${filename}".xls`... – l'L'l Mar 14 '17 at 05:16
  • 1
    You might have guessed what is the problem with `"${filename}.xls ${filename}.csv"` ie `ssconvert` would consider the entire stuff as one argument. The change should work though. :) – sjsam Mar 14 '17 at 05:20
  • @sjsam, Yeah I'm not familiar with how ssconvert deals with the output types, so I assumed that might've been the issue - thx! – l'L'l Mar 14 '17 at 05:21
  • BTW, the error imho has nothing to do with `ssconvert`, it is just that the second argument was missing with the previous version of this answer. Note that [\[ comment#1 \]](http://stackoverflow.com/questions/42778112/how-to-convert-xls-to-cvs-in-unix#comment72670983_42778160) says `An output file name... is required` – sjsam Mar 14 '17 at 05:23
  • 1
    @sjsam: Yep definitely... I've been away for a bit, so literally "spaced it". – l'L'l Mar 14 '17 at 05:29
  • 2
    @Midhun : You may accept the answer if it worked. That is the official way of saying Thank you here :) – sjsam Mar 14 '17 at 05:40
  • Is there a way to convert xlsx with multiple tabs to csv. Least case i want to convert 1st tab. – Midhun Mar 16 '17 at 05:09
  • @Midhun: Ask a new question regarding that. – l'L'l Mar 16 '17 at 05:18