Wednesday, June 15, 2011

How to view (Windows) line ending characters on Mac OSX

Notepad++ on windows has this beautiful option "View all characters" to display all invisbile characters such as line endings.




Programming editors on mac like Textwrangler and Textmate has an option to Show Invisibles but failed to display the character block for Carriage Return as Notepad used to.

Textwrangler beats Textmate on this case where it display two special characters to refer CR and LF, where Textmate display only one character.

Textwrangler

Textmate


Our recent iPad project write csv file which is further parsed by a third party app. The 3rd party app requires the line ending to be a combination of Carriage Return (CR) and Line Feed(LF) instead of just Line Feed (LF) as traditional Unix/Mac. To test the csv generated is good, I had to view the character myself in any other editor.

After few failed attempts with both Textwrangler and Textmate, I came across this powerful unix tool called OctalDump (od) which is part of OSX.

od -c filename.csv

will display the file with C-Style escaped characters. CR as \r and LF as \n. It has numerous no. of options to explore.




5 comments:

  1. Thanks for sharing this Dr P, very helpful
    Mike

    ReplyDelete
  2. Text Wrangler is sadly no longer available - do you know of any alternatives?

    ReplyDelete
    Replies
    1. command 'od' as mentioned in the post is an alternative

      Delete