When working with some data files on Linux, it is sometimes necessary to filter out the blank lines in the system, which can be done by the various tools available in the systems. The usual introduction is as follows: 1. Grep
View Code BASH
123 |
Grep. Data.txtgrep-v ' ^$ ' data.txtgrep ' [^$] ' data.txt |
2. Sed
View Code BASH
123 |
The sed '/^$/d ' data.txtsed '/^\s*$/d ' data.txt #这个命令还可将完全空格, tab and other blank lines are deleted. # The character class \s would match the whitespace characters <tab> and <space>. |
3. awk
View Code BASH
12 |
awk NF data.txt # This also allows blank lines, such as spaces, tabs, and so on, to be deleted. awk '!/^$/' data.txt |
4. TR
View Code BASH
Seemingly these can handle the commands inside, "grep." Data.txt "The efficiency of this is relatively high; you can compare the performance of some of these commands when dealing with large amounts of data.
- This article is from: Linux Learning Network
Ways to delete empty rows on Linux