How to Remove all empty lines in a file on Linux and Windows?
Remove empty lines from file.txt via Linux command line
- Option 1: sed -i '/^$/d' file.txt
- Option 2: awk 'NF > 0' file.txt > output.txt
- Option 3: perl -i.backup -n -e "print if /\S/" file.txt
- Option 4: grep . file.txt > output.txt
Remove empty lines from file.txt using Powershell script on Windows
(gc file.txt) | ? {$_.trim() -ne "" } | set-content file.txt
Level up your Tech Career with DjamgaTech PRO
Download the DjamgaTech PRO App on the Apple App Store to access hundreds of interactive prep questions, flashcards, and quizzes cleanly without ads.
Advertisement
Download DjamgaTech PRO on the App Store 🚀
← All articles