The use of grep,sed in Linux

Source: Internet
Author: User

Today, Mayuyu Some of the commands that are commonly used in Linux.

1. grep command

grep is used to filter what you need, and the syntax is as follows

grep Mayuyu--color

Filters out all rows that contain Mayuyu, and grep also supports regular expressions.

2. SED command

There are two main issues when editing a file using the normal VIM editor

(1) When the file is relatively large, you need to open the file, occupy a large amount of memory.

(2) When editing a file, you must interact, so it is difficult to call vim and so on.

Sed belongs to the stream editor, the so-called stream editor is in the editing of files, you can not have to read the entire file into memory, you can line a

Read in, and then read the next line when the operation is complete, which takes up less memory.

The most commonly used command is the substitution of strings, such as in a file, you need to replace a string with another string, the command is as follows

Indicates that var in the Hello.cpp file is replaced with ans, and the characters that need to be replaced are enclosed in \< and \> .

Displays a string in the first line of the original file, using the following command

The line that starts with int is the 7th line in the source file, and the line is displayed with "=".

Learn more about the SED reference:http://www.cnblogs.com/edwardlost/archive/2010/09/17/1829145.html

The use of grep,sed in Linux

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.