Use BBedit to replace CR with LF
Asked Answered
R

2

5

I have a text file where I would like to change all the Carriage Return to Line Feed. I am working on a Mac, and it seems like BBedit should be able to easily do this. However, in the search function it does not appear to differentiate between CR (\r) and LF (\n). Searching for either character gets the same hits, and a search for "\r" to replace with "\n" does not work.

Is there some other way to represent CR and LF, so that BBedit can differentiate between them?

Ranit answered 4/11, 2019 at 20:31 Comment(1)
This is a great question but not for Stack Overflow, which is about programming, not about how to use a certain piece of software. The simple answer is there's a menu at the bottom of the window that lets you specify the line ending type; just flip that to Unix line endings and save the file. Alternatively use the menu in the Save As dialog.Puppetry
P
4

A possibly simpler way to do this is to make sure you enable "Line Break Types" in BBedit's Preferences -> Appearance.

This will add a Line Types popup menu at the bottom of the window.

Not only does it show you what the current format is, but it makes it trivial to switch between them.

(I also turn on "Text Encoding" as well, in case I need to switch between UTF8 and UFT16 and others.)

Pericline answered 2/12, 2022 at 0:43 Comment(1)
I am pretty sure this used to be on by default – I was quite disappointed to see it gone. Thanks for the heads-up!Rennie
C
3

For a single file:

  • Text -> Apply Text Transform
  • Select Change Line Endings
  • Click the Configure button and choose your desired line endings

For multiple files:

  • File -> New -> Text Factory
  • Select Change Line Endings
  • Click the Options button and choose your desired line endings
  • Save the Text Factory and apply it to the files you want changed through the Choose and Options buttons
Cotenant answered 22/11, 2019 at 3:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.