Shell removes empty rows

Source: Internet
Author: User

There are many blank lines after extracting the log files to be viewed recently, which is not conducive to the comparison of previous files. In order to be backward compatible, only empty lines can be deleted when obtained. I googled myself and used the grep method. The efficiency was quite fast. There were 73 blank lines in more than 25000 rows. I should be able to take over the lines in an instant.
Method 1: (I used this)
Grep-V "^ $" file removes matching empty rows
In addition, you can also use grep to view the rows that are empty during troubleshooting, so that you can view the behavior information from the original log file,
Add the parameter-N grep-n "^ $" file to find the empty line and view the information in the original log file.


Method 2: Use the tr command
Cat file name | tr-s '\ N'

Method 3: Use the SED command
Cat file name | sed '/^ $/d'

Method 4: Use the awk command
Cat file name | awk '{if ($0! = "") Print }'
Cat file name | awk '{If (length! = 0) Print $0 }'

Shell removes empty rows

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.