Linux filters empty lines in old files and comment lines remaining content to form a new file

Source: Internet
Author: User
I. Description

In some scenarios we want to filter out the empty lines and comment lines of old files, leaving the rows that produce the actual effect.

For example, there are a lot of blank lines and comment lines in the configuration sample file provided by Redis, and we want to filter out the configuration lines that produce the actual effect to form a new concise configuration file.

Second, the order

grep " ^$|# " old_file_name > New_file_name

grep--filtering commands

-e--using regular expressions to match

-v--culling of matching items (by default, filter matching items)

^--opening match

$--represents a blank line

|--or operations in a regular

#--#开头行

old_file_name--file to filter its contents

new_file_name--filtered content saved to the text pins XLR

Iii. examples

Reference:

https://www.zhihu.com/question/19795238

Linux filters empty lines in old files and comment lines remaining content to form a new file

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.