4

How can I go about remove carriage returns from a file in a text editor?

For example, if I start with this:

Hello
world
this
is
an
example

I'd like to end up with:

Hello world this is an example

How do I do this in Text Editor and Notepadqq in Ubuntu 16.04 LTS?

5

This is easy to do in Ubuntu's default text editor gedit a.k.a. Text Editor.

Open Find and Replace menu by using the default Ctrl+H key shortcut or by using the context menu in the top right of gedit.

  1. If you are editing a file with UNIX-style line endings, do a find & replace like so:

    Find: \n
    Replace with: space

    Find and Replace dialog box, searching for Unix-style (LF) line endings


  1. If you are editing a file with Windows-style line-endings, do a find & replace like so:

    Find: \r\n
    Replace with: space

    Find and Replace dialog box, searching for Windows-style (CRLF) line endings

  • @EliahKagan even if it doesn't work in Notepadqq, OP could still copy/paste into gedit... shrug – Android Dev Sep 24 '17 at 11:27
  • I believe the OP may have been interested in how to do it in multiple editors, based on the original wording in the question--that's why I was asking. (In some desktop environments, gedit appears in menus as "Text Editor.") This answer is definitely valuable. I've added a heading so people know this is gedit. @HidekiNishimura I've edited your question to make it say what I think you had intended. But if that is not correct, please feel free to roll back my edit or otherwise edit again. – Eliah Kagan Sep 24 '17 at 12:10

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.