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

  • sed
  • grep
  • awk

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