Remove carriage return from output in Sublime Text 3
Asked Answered
V

1

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

Vistula answered 6/11, 2015 at 20:52 Comment(4)
What does file names/yob1880.txt say? Maybe try dos2unix or sed -e 's/\r//'...Maggoty
@Maggoty 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.Vistula
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 a \r with an empty string in regexp mode?Maggoty
@Maggoty 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"Vistula
R
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" }

Resigned answered 22/5, 2019 at 9:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.