7

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?

Eliah Kagan
  • 116,445
  • 54
  • 318
  • 493
Hideki Nishimura
  • 679
  • 6
  • 10
  • 13

1 Answers1

8

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

αғsнιη
  • 35,092
  • 41
  • 129
  • 192
You'reAGitForNotUsingGit
  • 14,669
  • 9
  • 48
  • 83
  • @EliahKagan even if it doesn't work in Notepadqq, OP could still copy/paste into gedit... *shrug* – You'reAGitForNotUsingGit 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