Get the App
SLTechnology News&Howtos  ›  Servers  › 

Sed usage

Shulou Source: shulou.com Published: 2022-06-03 02:02:08 11月16日 Update

Sed syntax

Sed [OPTION]... {script-only-if-no-other-script} [input-file]...

Sed is a file line processing tool

It is a single-line processing that reads the first line of the file to the pattern space, which is equivalent to the station of the factory pipeline.

There is also a holding space, which is equivalent to h storing temporary data in the schema space and the data in the holding space can be adjusted, such as appending the data replication of the schema space to the holding space. Gju

Since sed is a text processing tool, what is the use of the right?

1sed can modify the contents of a line

There must be a standard for modifying the contents. How do you define a line of characters in a document?

For example, the beginning of a line is represented by ^ and the end of a line is represented by $.

Represents a word boundary\

< \>

\ b\ b

Words are defined as letters, underscores, numbers that make up any other character that can be thought of as the boundary of a character.

Modifying the data of a row must match the characters of the row before it can be modified.

1 first line

Line 1 and line 2

1x 2 means odd lines.

2an even number of lines

You can also match through regular expressions.

To match the line at the beginning of root and print it out

You can also use two regular expressions.

Sed-rn'/ regular 1According to the line from the first regular beginning to the first regular 2 in the text and printing

-n turn off default output to the terminal

P print matching lines to the terminal

An append the content to the matching line

I insert content in front of the match

C means to replace matching lines

R read the contents of the specified file to match

W store the matching lines in the specified file

-e supports modification of multiple points

-r supports extended regular expressions

-I modify the file and take effect without adding the option means that it is only displayed on the terminal and does not modify the file.

Fill in regular expressions between s# search and replacement #

G stands for global replacement

Sed syntax

Sed 'delimited matching command' file.

Tags: File regular space content data character expression line pattern terminal processing word tool text grammar boundary support underscore between two Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Huawei vpn Shulou Technology macOS