User Tools

Site Tools


ubuntu:file:delete_empty_lines

This is an old revision of the document!


Ubuntu - File - 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 
ubuntu/file/delete_empty_lines.1594805433.txt.gz ยท Last modified: 2020/07/15 09:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki