Ways to delete empty rows on Linux

Source: Internet
Author: User

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

Tr-s ' \ n ' < Data.txt

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.