Sed, linuxsed command

Source: Internet
Author: User

Sed, linuxsed command

Sed is an online editor that processes a row of content at a time. During processing, the currently processed rows are stored in the temporary buffer, called the pattern space. Then, the sed command is used to process the content in the buffer, send the buffer content to the screen. Next, process the next row, and repeat until the end of the file. The file content is not changed unless you use the redirection storage output. Sed is mainly used to automatically edit one or more files, simplify repeated operations on files, and write conversion programs. The following describes the Gnu Sed 3.02 version.
2. Addressing

The address can be used to locate the row you want to edit. The address is composed of numbers, the two rows separated by commas indicate the range of rows starting and ending with the two rows (including the rows indicated by the number of rows ). For example, 1 and 3 indicate 1, 2, 3 rows, and the dollar sign ($) indicates the last row. The range can be determined by data, regular expressions, or a combination of the two.
3. Sed command

The sed command can be called in two forms:
Sed [options] 'command' file (s)
Sed [options]-f scriptfile file (s)
A \ adds a line of text behind the current line.
B lable branch to the marked place in the script. If the branch does not exist, it is routed to the end of the script.
C \ use new text to change the text of this line.
D. Delete the row from the position of the template block (Pattern space.
D. Delete the first line of the template block.
I \ insert text on the current row.
H. Copy the content of the template block to the buffer in the memory.
H append the content of the template block to the buffer in the memory.
G obtains the content of the memory buffer and replaces the text in the current template block.
G to obtain the content of the memory buffer and append it to the end of the block Text of the current template.
L The list cannot print the character list.
N. Read the next input line and use the next command to process the new line instead of the first command.
N append the next input row to the template block and embed a new line between them to change the number of the current row.
P prints the row of the template block.
P (uppercase) prints the first line of the template block.
Q: Exit Sed.
R file reads rows from the file.
The t labelif branch starts from the last line. Once the condition is met or the T and t commands are executed, the Branch is routed to the command with a label or to the end of the script.
T label indicates the branch with an error. Starting from the last line, once an error occurs or the T and t commands are executed, the Branch is routed to the command with a label or to the end of the script.
W file write and append the template block to the end of the file.
W file write and append the first row of the template block to the end of the file.
! Indicates that the subsequent commands will work on all unselected lines.
S/re/string Replace the regular expression re with string.
= Print the current row number.

Extend the annotation to the next line break.

Replace tags
G indicates that all rows are replaced.
P indicates printing rows.
W indicates writing rows into a file.
X indicates the text in the SWAp template block and the text in the buffer.
Y indicates translating a character into another character (but not used in regular expressions)
4. Options

-E command,-expression = command
Multiple edits are allowed.
-H,-help
Print help and display the address of the bug list.
-N,-quiet,-silent
Cancel default output.
-F,-filer = script-file
The name of the bootstrap sed script file.
-V,-version
Print the version and copyright information.
5. metacharacters

^
The start of the anchor row is as follows:/^ sed/matches all rows starting with sed.
The end of the anchor row is as follows:/sed /Match all rows ending with sed.
.
Match a non-linefeed character, for example,/s. d/match s, followed by any character, and then d.
*
Match zero or multiple characters, such as:/* sed/match all templates with one or more spaces followed by sed rows.
[]
Matches a character in a specified range, such as/[Ss] ed/matches sed and Sed.
[^]
Match a character that is not within the specified range, such as:/[^ A-RT-Z] ed/match a line that is followed by a letter that does not contain a A-R and a T-Z.
(..)
Save matching characters, such as s/(love) able/\ 1rs. loveable is replaced with lovers.
&
Save search characters to replace other characters, such as s/love/&/, Love.Love.
\ <
Anchor specifies the start of a word, for example :/\

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.