Linux Three Musketeers-------sed command

Source: Internet
Author: User

sed command file Edit Document index [hide] sed option, command, replace mark option parameter sed command sed replace mark sed meta character set SED usage instance replace operation: s command full replacement Mark G delimiter delete operation: D command matched string tag & substring match label \1 combine multiple expressions to refer to the range of the selected row:, (comma) multipoint edit: E command reads from file: R command to write file: w command Append (line): a\ command Insert (line): I\ command Next: N Command variant: y command exit: q command to keep and get: H command and G command to keep and swap: h command and x command script ScriptFile print odd lines or even lines to print the next line of matched strings sed is a flow editor, which is a very useful tool in text processing, perfect for use with regular expressions, and features are extraordinary. When processing, the currently processed rows are stored in a temporary buffer called pattern space, followed by the SED command to process the contents of the buffer, and after processing is done, the contents of the buffer are sent to the screen. Then the next line is processed, so it repeats until the end of the file. The file content does not change unless you use redirection to store the output. SED is mainly used to automatically edit one or more files, to simplify the repeated operation of the file, to write the conversion program and so on. sed options, commands, replace Mark command format sed [options] ' command ' file (s) sed [options]-F scriptfile file (s) option-esed command file edit index [hide] sed options, life Order, replace mark option parameter sed command sed replace mark sed meta character set SED usage instance replace operation: s command full replacement Mark G delimiter delete operation: D command matched string tag & substring match tag \1 combination multiple expressions reference the range of the selected row:, (comma) multipoint EDIT: E command read from file: R command to write file: w command Append (line): a\ command Insert (line): I\ command Next: N Command variant: y command exit: Q command Hold and get: H command and G command hold and Swap: H command and x command script ScriptFile print odd line or even Line print Match string the next line of SED is a flow editor, which is a very useful tool in text processing, perfect for use with regular expressions, and features are extraordinary. When processing, the currently processed row is stored in a temporary buffer called pattern space, followed by the SED command to process the contents of the buffer, after processing is completed, the bufferThe contents of the area are sent to the screen. Then the next line is processed, so it repeats until the end of the file. The file content does not change unless you use redirection to store the output. SED is mainly used to automatically edit one or more files, to simplify the repeated operation of the file, to write the conversion program and so on. sed options, commands, replace Mark command format sed [options] ' command ' file (s) sed [options]-F scriptfile file (s) option-E Introduction

Sed is an online editor that processes a single line of content at a time. When processing, the currently processed rows are stored in a temporary buffer called pattern space, followed by the SED command to process the contents of the buffer, and after processing is done, the contents of the buffer are sent to the screen. Then the next line is processed, so it repeats until the end of the file. The file content does not change unless you use redirection to store the output. SED is mainly used to automatically edit one or more files, to simplify the repeated operation of the file, to write the conversion program and so on.

The process of SED is simplified after this:

1. Read the new line into the cache space;

2. Remove the first instruction from the specified operation instruction to determine if the pattern is matched;

3. If it does not match, then ignore the subsequent editing commands, go back to the 2nd step and continue to remove the next instruction;

4. If matching, follow-up editing commands are executed for the cached rows; After completion, go back to the 2nd step and proceed to the next instruction;

5. When all instructions are applied, output the contents of the cache line, and go back to the 1th step to continue reading the next line of content;

6. When all lines have been processed, end;

See the specific process:

[[Email protected] ~]# sed [-NEFR] [action]
Options and Parameters:
-N: Use Quiet (silent) mode. In the usage of general sed, all data from STDIN is generally listed on the terminal. However, if you add the-n parameter, only the line (or action) that is specially processed by SED is listed.
-E: Action editing of SED directly in command-line mode;
-F: The action of SED is written directly in a file, and-f filename can run the SED action within filename;
-r:sed's actions support the syntax of extended formal notation. (The default is the basic formal French notation)
-I: Directly modifies the contents of the read file, not the output to the terminal.

Action Description: [n1[,n2]]function
N1, N2: Not necessarily exist, generally represents "select the number of lines of action", for example, if my action is required between 10 to 20 rows, then "10,20[Action Behavior"

function
A: New, a can be followed by a string, and these strings will appear in a new line (the current next line) ~
C: Replace, C can be followed by strings, these strings can replace the line between N1,N2!
D: Delete, because it is deleted ah, so d usually do not pick up any boom;
I: Insert, I can be followed by the string, and these strings will appear on a new line (the current line);
P: Print, that is, print out a selected data. Normally p will run with the parameter Sed-n ~
S: Replace, can be directly replaced by work! Usually this s action can be paired with formal notation! For example 1,20s/old/new/g is!

Sed delete entire row

Delete 2-4 lines of code, D delete
[Email protected]:~/work$ nl a1.txt | Sed ' 2,4d ' 1hello 5nihao 6nihao 7nihao
Remove the last row from the third line
[Email protected]:~/work$ nl a1.txt 1hello 2hello 3world 4nihao 5nihao 6nihao 7nihao [Email protected]:~/work$ nl a1.txt | Sed ' 3, $d ' 1hello 2hello

http://www.runoob.com/linux/linux-comm-sed.html
View Code

A\ inserts text below the current line. I\ inserts text above the current line. C\ changes the selected line to a new text. d Delete, delete the selected row. D Delete the first line of the template block. s replaces the contents of the specified character H copy template block into an in-memory buffer. H appends the contents of the template block to the in-memory buffer. G Gets the contents of the memory buffer and overrides the text in the current template block. G gets the contents of the memory buffer and appends it to the text of the current template block. The list of characters cannot be printed. N reads the next input line, processing the new row with the next command instead of the first command. N appends the next input line to the template block and embeds a new line between them, changing the current line number. P Prints the line of the template block. P (uppercase) prints the first line of the template block. Q Exit sed. b lable branches to the markup in the script, branching to the end of the script if the branch does not exist. R file reads rows from file. The T-label if branch, starting from the last row, will cause the branch to be at the command with a label, or to the end of the script, once the condition satisfies or t,t the command. The T label Error branch, starting with the last line, will cause the branch to be at the command with a label, or at the end of the script, once an error or T,T command occurs. W file writes and appends the template block to the end of file. W file writes and appends the first line of the template block to the end of file. Indicates that the subsequent command has effect on all rows that are not selected. = Prints the current line number. # extend annotations before the next line break.

From: http://man.linuxde.net/sed

sed command file Edit Document index [hide] sed option, command, replace mark option parameter sed command sed replace mark sed meta character set SED usage instance replace operation: s command full replacement Mark G delimiter delete operation: D command matched string tag & substring match label \1 combine multiple expressions to refer to the range of the selected row:, (comma) multipoint edit: E command reads from file: R command to write file: w command Append (line): a\ command Insert (line): I\ command Next: N Command variant: y command exit: q command to keep and get: H command and G command to keep and swap: h command and x command script ScriptFile print odd lines or even lines to print the next line of matched strings sed is a flow editor, which is a very useful tool in text processing, perfect for use with regular expressions, and features are extraordinary. When processing, the currently processed rows are stored in a temporary buffer called pattern space, followed by the SED command to process the contents of the buffer, and after processing is done, the contents of the buffer are sent to the screen. Then the next line is processed, so it repeats until the end of the file. The file content does not change unless you use redirection to store the output. SED is mainly used to automatically edit one or more files, to simplify the repeated operation of the file, to write the conversion program and so on. sed options, commands, replace Mark command format sed [options] ' command ' file (s) sed [options]-F scriptfile file (s) option-esed command file edit this article index [hide] sed options, command, replace mark option parameter sed command sed replace mark sed meta character set SED usage instance replace operation: s command full replacement Mark G delimiter delete operation: D command matched string tag & substring match tag \1 combination multiple expressions reference the range of the selected row:, (comma) multiple Point edit: E command reads from file: R command to write file: w command Append (line): a\ command Insert (line): I\ command Next: N Command variant: y command exit: Q command Hold and get: H command and G command keep and swap: H command and x command script ScriptFile print odd line or even Number of lines to print the next line of matching strings sed is a flow editor, which is a very useful tool in text processing and is perfect for use with regular expressions. When processing, the currently processed row is stored in a temporary buffer, called the pattern space, followed by the SED command to process the contents of the buffer, after processing is completed, the slowThe contents of the Flushing area are sent to the screen. Then the next line is processed, so it repeats until the end of the file. The file content does not change unless you use redirection to store the output. SED is mainly used to automatically edit one or more files, to simplify the repeated operation of the file, to write the conversion program and so on. sed options, commands, replace Mark command format sed [options] ' command ' file (s) sed [options]-F scriptfile file (s) option-E

Linux Three Musketeers ' second-------sed command detailed

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.