How to remove carriage returns in a text editor?

11,331

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

Share:
11,331

Related videos on Youtube

Hideki Nishimura
Author by

Hideki Nishimura

Updated on September 18, 2022

Comments

  • Hideki Nishimura
    Hideki Nishimura over 1 year

    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?

  • You'reAGitForNotUsingGit
    You'reAGitForNotUsingGit over 6 years
    @EliahKagan even if it doesn't work in Notepadqq, OP could still copy/paste into gedit... shrug
  • Eliah Kagan
    Eliah Kagan over 6 years
    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.