6

I'm learning ipython for data analysis and I'd like to use Sublime text, my favorite text editor. However, I'm having a problem with "CR", carriage return, being output instead of the original "stuff" I want to display. This makes copying/pasting to another location a hassle because I'll have to manually delete those characters. It's also frustrating to look at.

Here's an example from the textbook I'm using: sublime output

Running the same command in terminal and it works fine Terminal output of same command

Although it displays properly in terminal, I really would like to use a REPL in sublime because of the helpful plugins such as autocomplete and code intelligence. I've tried changing the user settings default_line_ending but nothing helped. If someone knows how to get rid of those carriage returns or at least hide them from the output, I'd be very happy.

Thank you

Maurice Abney
  • 223
  • 3
  • 14
  • What does `file names/yob1880.txt` say? Maybe try `dos2unix` or `sed -e 's/\r//'`... – Kenney Nov 06 '15 at 20:59
  • @Kenney Thanks for the comment. It's just a plaintext file with name, gender, amount of births on each line. I tried converting to unix but I'm still getting the CR's in the output. – Maurice Abney Nov 06 '15 at 21:26
  • Okay. The `file` command on a plain text file with unix line endings would say 'ASCII Text'; for a DOS file 'ASCII Text, with CRLF line terminators', and in your case I wouldn't know what it says. It looks to me the line endings are CRCRLF (`\r\r\n`, you could verify with `hexdump -C`: there would be `0d 0d 0a` patterns), and need to be fixed; there's no setting in any editor that I know that fixes that. Do you know how to [search and replace](http://docs.sublimetext.info/en/latest/search_and_replace/search_and_replace.html) a `\r` with an empty string in regexp mode? – Kenney Nov 06 '15 at 21:46
  • @Kenney didnt realize that was a command, the output is "names/yob1880.txt: ASCII text, with CRLF line terminators". Also there are no "0d 0d 0a" patterns in the hexdump, just "0d 0a" – Maurice Abney Nov 06 '15 at 21:58

1 Answers1

3

If your terminal supports it, you can try the following command to remove the existing CRs:

sed -i 's/\r//g' FileWithCarriageReturns.foo

sed is a stream editing command which when executed as above, will search through the specified 'FileWithCarriageReturns.sh' and remove all carriage returns (seen as \r ) from the file

Once you've done that, go into your Sublime Text settings and override the default line ending property to be 'unix' :

{ "default_line_ending" : "unix" }