about how SED is used

Source: Internet
Author: User

Sed is one of the Three Musketeers of the Linux command, which is the abbreviation of Stream editor, and the meaning is the abbreviation of the flow editors.

It is good at fetching, replacing, filtering. This is a bit like awk, but awk is fetching columns, but SED is fetching.

Usage: sed-n '/filtered content/processed commands/' filename

-N is the default output for canceling sed.

-P is the meaning of printing.

-I changes the contents of the file.

-R fruit does not need r parameters in regular expressions to use a lot of \ To cast, if you use R can directly write regular expressions, rather than write so many \

= line number can be represented.


SED is replaced by a wide range of applications.

s refers to commonly used find and replace, replacing one string with another.

G is used in conjunction with S, which represents a global match substitution for the current row (different from the next G meaning), and if you do not add a G to replace the first column, it is not replaced globally.

#是分隔符, you can replace them with other symbols.

-I is replaced and modified.

The format is: sed ' s## #g '

Example: sed ' s#oldboy#oldgirl#g ' test.txt but only the content of the output is modified, and the file entity is not modified.

Sed-i ' s#oldboy#oldgirl#g ' test.txt plus-I can change the content.

find/root/data/-type f-name "test.txt" |xargs sed ' s#oldboy#oldgirl#g ' is an example of a combination of find and sed replacements,

Use the SED command to remove the IP address within the ifconfig:

Ifconfig Eth0|sed-nr ' s#^.*addr: (. *) B.*$#\1#GP '


about how SED is used

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.