Text Cleanup

Remove Empty Lines

Quickly strip out all empty or whitespace-only lines from a text block.

Explanation

Useful for cleaning up messy logs, data exports, or code where unnecessary gaps make it hard to read.

Examples

Messy List
Input
Item 1


Item 2
   
Item 3
Output
Item 1
Item 2
Item 3

Code Examples

JavaScript
const cleanText = input.split('\n')
  .filter(line => line.trim() !== '')
  .join('\n');
Python
clean_lines = [line for line in input_text.splitlines() if line.strip()]
output_text = "\n".join(clean_lines)

Try it Now

💡 Tips

  • Use trim() to also catch lines that only contain spaces
  • Great for preparing lists for bulk processing
  • Can significantly reduce file size for large text files

⚠️ Common Pitfalls

  • Sometimes empty lines are meaningful (e.g., separating paragraphs)
  • Be careful not to join text that needs visual separation