1

I already posted this on askdifferent, but no luck. Glad to remove if out of scope.


So I am running some Python scripts that print out tab-delimited data (i.e. adding the \t character during the print command).

Problem

  • I am trying to copy that tab-delimited data from the shell / Terminal into Excel Mac or other spreadsheet applications, hoping they would recognize the tab-delimination and put the items into separate cells

This does not work; however, if I copy the text into an editor such as Atom or Emacs first, and then into Excel, it recognizes the tabs as delimiters.

  • Why does it work with the additional step?
  • Do the text editors change the nature of the tabs, and how can I emulate this behavior within the Terminal?

Example:

print "123\tbeetle\t12.4\n200\tbutterfly\t1.2\n"

Result:

Copy from Terminal into Excel:

Copy into Excel directly

Copy from Terminal to Text Editor, then into Excel:

Copy via Text Editor

Any help is much appreciated! I know there are more elegant ways of doing this, but this is still something I'd like to figure out.

I found a somewhat similar, but unresolved question here.

Running Python 2.7.13 , Sierra 10.12.6, Excel 2016 for Mac

2

It's presumably a limitation of your terminal application. In comparison, tabs copy fine from my (Linux) terminal. Perhaps you could try a different emulator? (I've heard good things about iTerm2.)

Alternatively, you could directly pipe into the clipboard. I believe the command on OS X is pbcopy. i.e.

print "123\tbeetle\t12.4\n200\tbutterfly\t1.2\n" | pbcopy
  • 1
    pbcopy totally does it. Thank you for your help! – patrick Feb 15 '18 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.