delete empty lines

Take out the empty lines of a file, also the ones with only spaces.

text

steps
  1. sed -i '/^$/d' file.txt

    delete the empty lines

  2. sed -i '/^[[:space:]]*$/d' file.txt

    also the lines with only spaces or tabs

  3. grep -v '^$' file.txt > new.txt

    write the file without them to a new one

  4. awk 'NF' file.txt

    show it without empty or blank lines

notes
  • macOS: sed -i '' in place of sed -i.
commands used

sedgrepawk

Each has a page in lore: lore sed opens it.