I'm playing around with xls2csv (part of the catdoc application).
Something simple like: xls2csv -c~ products.xls > products.txt
does what I'd expect (exports the XLS, using "~" as the field separator).
Any suggestions how I can make this create a tab separated file instead?
I think this is more about how to pass the TAB through the shell (ie more to do with bash than xls2csv) but I could be wrong.
On Fri, Aug 11, 2006 at 01:41:05PM +0100, Mark Rogers wrote:
I'm playing around with xls2csv (part of the catdoc application).
Something simple like: xls2csv -c~ products.xls > products.txt
does what I'd expect (exports the XLS, using "~" as the field separator).
Any suggestions how I can make this create a tab separated file instead?
I think this is more about how to pass the TAB through the shell (ie more to do with bash than xls2csv) but I could be wrong.
In some other tools I've used "\t" (sans quotes) to indicate a tab.
Dunno if that works in xls2csv though.
Cheers, Al.
Alan Pope wrote:
In some other tools I've used "\t" (sans quotes) to indicate a tab.
Dunno if that works in xls2csv though.
I tried that originally, but no joy. It ends up in the document as just "t".
I also tried \t and various quoting.
Jan T. Kim wrote:
In an interactive bash, use Ctrl-V to quote the tab (i.e. to protect it from being interpreted as a request of command / filename completion).
This is a general feature of interactive programs based on readline, I believe.
I didn't know this trick, but it did allow me to put the tab into the commandline. My first attempt failed since I didn't quote it (and the commandline interpreter stripped the whitespace), but putting it in quotes did work. So thanks - that seems to be what I need.
I did previously try -c$(echo -ne '\t') .. but that didn't work for exactly the same reasons; sure enough had I thought to try: -c"$(echo -ne '\t')" .. that also works.
Which makes it all sort of academic since I'll actually build the commandline from a PHP script so inserting a genuine TAB will be no problem, but the Ctrl-V trick is a good one to know about. Thanks!
[Background: I got tired of telling people to convert their XLS files into tab-separated-variable files because its surprising just how frequently they screw that up. Combining a proprietary file format with a user is a recipe for failure!]
Alan Pope wrote:
In some other tools I've used "\t" (sans quotes) to indicate a tab.
Dunno if that works in xls2csv though.
I tried that originally, but no joy. It ends up in the document as just "t".
I also tried \t and various quoting.
Jan T. Kim wrote:
In an interactive bash, use Ctrl-V to quote the tab (i.e. to protect it from being interpreted as a request of command / filename completion).
This is a general feature of interactive programs based on readline, I believe.
I didn't know this trick, but it did allow me to put the tab into the commandline. My first attempt failed since I didn't quote it (and the commandline interpreter stripped the whitespace), but putting it in quotes did work. So thanks - that seems to be what I need.
I did previously try -c$(echo -ne '\t') .. but that didn't work for exactly the same reasons; sure enough had I thought to try: -c"$(echo -ne '\t')" .. that also works.
Which makes it all sort of academic since I'll actually build the commandline from a PHP script so inserting a genuine TAB will be no problem, but the Ctrl-V trick is a good one to know about. Thanks!
[Background: I got tired of telling people to convert their XLS files into tab-separated-variable files because its surprising just how frequently they screw that up. Combining a proprietary file format with a user is a recipe for failure!]
On 11-Aug-06 Alan Pope wrote:
On Fri, Aug 11, 2006 at 01:41:05PM +0100, Mark Rogers wrote:
I'm playing around with xls2csv (part of the catdoc application).
Something simple like: xls2csv -c~ products.xls > products.txt
does what I'd expect (exports the XLS, using "~" as the field separator).
Any suggestions how I can make this create a tab separated file instead?
I think this is more about how to pass the TAB through the shell (ie more to do with bash than xls2csv) but I could be wrong.
In some other tools I've used "\t" (sans quotes) to indicate a tab.
Dunno if that works in xls2csv though.
Cheers, Al.
Assuming from the description that after
xls2csv -c~ products.xls > products.txt
the only occurrences of "~" in products.txt is as a field separator, you should be able to straightforwardly us 'tr' to change it to "\t":
xls2csv -c~ products.xls | tr "~" "\t" > products.txt
E.g.
$ cat temp A~B~C~D~E~F~G A~B~C~D~E~F~G A~B~C~D~E~F~G A~B~C~D~E~F~G A~B~C~D~E~F~G A~B~C~D~E~F~G
$ cat temp | tr "~" "\t" > temp2 $ cat temp2 A B C D E F G A B C D E F G A B C D E F G A B C D E F G A B C D E F G A B C D E F G
$ od -c temp2 0000000 A \t B \t C \t D \t E \t F \t G \n A \t 0000020 B \t C \t D \t E \t F \t G \n A \t B \t 0000040 C \t D \t E \t F \t G \n A \t B \t C \t 0000060 D \t E \t F \t G \n A \t B \t C \t D \t 0000100 E \t F \t G \n A \t B \t C \t D \t E \t 0000120 F \t G \n
just as it should be!
Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 11-Aug-06 Time: 14:38:03 ------------------------------ XFMail ------------------------------
On Fri, Aug 11, 2006 at 01:41:05PM +0100, Mark Rogers wrote:
I'm playing around with xls2csv (part of the catdoc application).
Something simple like: xls2csv -c~ products.xls > products.txt
does what I'd expect (exports the XLS, using "~" as the field separator).
Any suggestions how I can make this create a tab separated file instead?
I think this is more about how to pass the TAB through the shell (ie more to do with bash than xls2csv) but I could be wrong.
In an interactive bash, use Ctrl-V to quote the tab (i.e. to protect it from being interpreted as a request of command / filename completion).
This is a general feature of interactive programs based on readline, I believe.
Best regards, Jan