bash:files:delete_empty_lines
Table of Contents
BASH - Files - Delete empty lines
Using awk
awk 'NF' my_input > my_output
Using sed
Delete empty lines using sed.
sed '/^$/d' <input-file> echo "LINE" | sed '/^$/d' echo "$VAR" | sed '/^$/d' sed '/^[[:space:]]*$/d' input_file sed '/^$/d' input > output sed '/^\s*$/d' in > out sed -n '/^\s*$/!p' in.txt > out.txt sed '/^[[:space:]]*$/d' input > output
Examples
Delete all empty lines from a file
sed '/^$/d' /tmp/data.txt
Store output to another file use redirection operator
sed '/^$/d' /tmp/data.txt > /tmp/output.txt
Update the file directly
sed -i '/^$/d' /tmp/data.txt
bash/files/delete_empty_lines.txt · Last modified: 2022/06/13 10:29 by peter