Method One: Using grep
Grep-v ' ^\s*$ ' test.txt
Note:-V indicates that the matching result is reversed, and the regular expression matches the blank line. (blank lines can include whitespace characters such as character tabs)
Method two: Using SED
Sed '/^\s*$/d ' test.txt
Note: D represents the deletion of the row
Method Three: Using awk
awk NF Test.txt
Note: NF represents the number of fields in the current row, the number of fields in a blank line is 0, and awk is interpreted as false, so no output is made.
There are three ways to handle blank lines that contain whitespace characters (spaces, tabs, and so on).
Method Four: If the blank line is caused by ' \ n ', you can also use the TR command to remove the empty line
Tr-s ' \ n ' < test.txt
Note:-S represents the compression of multiple consecutive characters into a single character, where multiple ' \ n ' are compressed into a ' \ n ', which results in the removal of empty lines.
The level is limited, if has the improper place, also looks correct!
Linux Command (44): Remove empty lines from all files