Wrong characters from "tree" command

Using the standard "tree" command (as supplied by MacPorts), if at the Terminal prompt I cd to a folder and then execute "tree"there, I get output like this:


.
├── Activity\ Monitor.app
├── ApplicationsFolderIcon.icns
├── BBEdit.app
├── Backup
│   ├── Backup\ and\ Sync\ from\ Google.app
│   ├── Carbon\ Copy\ Cloner.app
│   ├── Dropbox.app\ 
│   ├── ForeverSave\ 2.app
│   ├── Get\ Backup\ Pro\ 3.app


However, if I redirect the output to a text file, as in


tree > myapps.txt


then I get wrong characters when I view the file in TextEdit:

.
├── Activity\ Monitor.app
├── ApplicationsFolderIcon.icns
├── BBEdit.app
├── Backup
│   ├── Backup\ and\ Sync\ from\ Google.app
│   ├── Carbon\ Copy\ Cloner.app
│   ├── Dropbox.app\ 
│   ├── ForeverSave\ 2.app
│   ├── Get\ Backup\ Pro\ 3.app


What's wrong?

iMac 27", macOS 10.15

Posted on Dec 10, 2019 9:33 AM

Reply

Similar questions

17 replies

Dec 10, 2019 11:42 AM in response to murrayE

tree -n --charset utf-8 > myapps.txt


Strip the color information [-n] from the UTF-8 output. This removes all of those prefaced color codes in TextEdit. Also, since TextEdit is not a proper programmer's editor, it will not align the output as it would if piped into BBEdit or more -r .


Here is the result from the preceding command when opened in BBEdit 13:


and in TextEdit:

Dec 10, 2019 1:15 PM in response to murrayE

murrayE wrote:

I'm still getting those weird characters such as │   ├──

Here's an analysis of what is happening: ├── is the utf-8 encoding for the drawing characters 251c 2500 2500 (e2 94 9c e2 94 80 e2 94 80) being read as if were in MacRoman encoding (which is presumably TextEdit's default).


I'm mystified by the error message you are getting.

Dec 10, 2019 8:42 PM in response to murrayE

murrayE wrote:

Yes,

tree -n --charset=unicode > ~/Desktop/myapps.txt

does work, too!

Thanks!


From the man page for tree, it appears that the "ascii" charset is probably CP437, an ancient 8 bit encoding which does have those drawing characters. I'm not sure how TextEdit would automatically recognize that. "Unicode" is probably utf-16, which TextEdit should be able to recognize without any help.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Wrong characters from "tree" command

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.