Ubuntu – How to remove carriage returns in a text editor

notepadqqtext-editortext;

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?

Best Answer

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

Related Question