delete empty lines
Take out the empty lines of a file, also the ones with only spaces.
Steps
-
sed -i '/^$/d' file.txtdelete the empty lines
-
sed -i '/^[[:space:]]*$/d' file.txtalso the lines with only spaces or tabs
-
grep -v '^$' file.txt > new.txtwrite the file without them to a new one
-
awk 'NF' file.txtshow it without empty or blank lines
Notes
- macOS:
sed -i ''in place ofsed -i.
Commands used
sedgrepawk
Each has a page in lore: lore sed opens it.
Related recipes
- add up numbers in a fileSum a column of numbers, from a file or a command's output.
- compare two foldersFind which files differ between two folders, or are only in one of them.
- count lines of codeHow many lines of code a project has, in total and by language.
- count lines, words and filesCount the lines of a file or of a command's output, the words, and the files in a folder.