Linux Delete empty line operations: awk, grep, tr, sed

Source: Internet
Author: User

Tag: enter lang \ \ Keep www www. How to enter blank

As follows: How to delete blank lines

Shen\nshen\\nsensehsehesheshe

To really delete empty lines, you can use VIM:

    • Delete empty lines through command mode. Vim in command mode (enter English characters in vim: Enter command mode) input: %s/^n//G. replaces all characters that begin with a carriage return, substituting null.
    • If you have more than one contiguous blank line, you want to keep a row. Then simply enter the following line in the command lines mode:%s/^n$//g

The Linux pipline output is the removal method:

1, grepgrep-v ' ^$ ' file2, sedsed '/^$/d ' file  or sed-n '/./p' file 3, awk: $ A line for awk '/./{print} ' File or awk ' {if ($0!= "") Print} '4"\ n"



Main reference: http://www.361way.com/del-blank-line/2225.html

Linux Delete empty line operations: awk, grep, tr, sed

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.