Version: @(#) $Id: rmemptylines.md,v 1.5 2026/04/17 07:51:25 ralph Exp $
Note
A smart Linux bash/shell utility to clean up text files cluttered with unnecessary blank lines, specifically designed to fix "double-spacing" caused by email clients like MS Outlook or over-enhanced MS Notepad garbling MarkDown.
rmemptylines [OPTIONS] <file>| Option | Mode | Description |
|---|---|---|
-b |
Backup | Creates a .bak copy of the original file before processing. |
-x |
Auto | (Default) Analyzes the file and automatically fixes Outlook-style double-spacing if detected. |
-s |
Squeeze | Collapses multiple consecutive blank lines into a single one. |
-d |
Double | Removes every even-numbered line only if it is empty (precise Outlook fix). |
-a |
All | Aggressive mode: Removes every single blank line, leaving no vertical space. |
-m |
MarkDown | Markdown cleanup, fixes MS Notepad escapes:  , \-, \#, etc. Thx MS! |
Clean up a MS Markdown file and create a backup before:
rmemptylines -m -b notes.mdFix a broken Outlook copy-paste (Auto-detect):
rmemptylines my_report.txtStrip every blank line and squeeze remaining gaps:
rmemptylines -a -s config.confReduce large gaps to single spaces:
rmemptylines -s messy_notes.logWarning
- In-place Editing: The tool overwrites the target file directly. Ensure you use the
-bflag if the data is critical. - Stacking Modes: You can combine multiple flags (e.g.,
-m -s) to perform successive cleanups in one command. - Pre-cleaning: The script automatically strips invisible trailing whitespace and tabs from lines before processing to ensure "empty" lines are correctly identified.
- Line Endings: Uses
flip(flip 1.20-5) to ensure the final file has consistent Unix-style line endings. You also can usedos2unixif your OS does not provide flip.
// END of document //