I've a file which holds empty lines, which I'd like to remove.

Is there a way to remove empty lines from Geany?

Note: I don't want to use another editor because I'm afraid it will add or change my csv format/encoding as I need to import these csv files as the format / encoding it is now.

enter image description here


If you insist to perform it inside geany editor - You can use geany lineoperations plugin which add the Remove Empty Lines feature to geany

A simpler way might be - to treat the file as a regular text file, and remove the empty lines using command-line tools (e.g. sed)

Here You can see several examples how to remove empty line from a text file.

Using sed:

sed '/^$/d' <input-file>

To delete all empty lines from a file called /tmp/data.txt, enter:

sed '/^$/d' /tmp/data.txt

To store output to another file use redirection operator:

sed '/^$/d' /tmp/data.txt > /tmp/output.txt

Note: Using sed to remove empty lines shouldn't change anything with the non-empty lines in file

Note: In order to modify the file in place you should use sed -i flag:

sed -i '/^$/d' <input-file>


The original text file:

$ cat in.txt 
This is a test

Linux rulez

Windows sucks
Ubuntu is good server disro

sed output when running on the file:

$ sed  '/^$/d' in.txt 
This is a test
Linux rulez
Windows sucks
Ubuntu is good server disro
  • I tried this command sudo sed -i '/^$/d' filename.csv. it doesn't remove empty lines for me. weird. – Zhenyu Jan 24 '18 at 15:34
  • 1
    @Zhenyu they may have whitespace in them – muru Jan 24 '18 at 15:35
  • 2
    @Zhenyu, Maybe your CSV text is a DOS formatted text file (created by Windows). It means that there are <carriage return><line feed> characters at the end of each line, not only <line feed> as in linux text files. – sudodus Jan 24 '18 at 15:55
  • 1
    @sudodus are you right, I got files from a client who's using windows... I guess that's why the expression is not working for me. – Zhenyu Jan 24 '18 at 16:02
  • 1
    @Zhenyu, You can use dos2unix to convert from a DOS formatted text file. Install with sudo apt install dos2unix from the repository 'universe'. – sudodus Jan 24 '18 at 17:55

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.