SED usage

xiaoxiao2021-03-06  45

The SED command column can be divided into edit instructions and file files. Among them, the editing instruction is responsible for controlling all editing work; the file file represents the file being processed. The editing instructions of the SED are each consisting of the address and function (function), where the SED uses its location parameters to determine the object of editing; and use its function parameters (solution [3 ])edit. In addition, the SED editing instruction can be executed within the file in addition to the command column. The difference is only to be executed on the command column, before it is necessary to add option -e; while in the file (solution [4]), simply add option -f before its file name. In addition, the SED performs editing instructions in accordance with them on the command column or in the order. In the following sections, the editing instructions, SED editing instructions on the command column will be introduced, and the editing instructions in the execution file, perform editing of multiple files, and perform SED output control. 2.1 End Editing Instructions 2.2 Sed Editing Instruction 2.3 Sid Editing Instruction 2.3 Operating Instructions 2.4 Performing a Multiple Archmarks 2.5 Performing SED Output Control 2.1. To perform the editing instructions on the command column When editing instructions (see [section 2.2]) When executed on the command column, you must add options -E. The format of its command is as follows: Sed -E 'Editor Directive 1' -e 'Editing Instruction 2' ... file files, all editing instructions are followed by option -e, and placed in two "'" special characters between. In addition, the execution of the editing instruction on the command is left and right. Generally, when the editing instruction is not allowed, the user usually executes them directly on the command. For example, delete 1 to 10 lines of information within YEL.DAT, and change the "Yellow" string in its text to the "Black" string. At this point, the editing instruction can be executed directly on the command, and the command is as follows: Sed -e '1, 10d' -e 's / yellow / black / g' YEL.DAT in the command, editing instructions '1, 10d' (Solution [5]) Execute 1 to 10 lines of data; editing instructions 's / yellow / black / g' (Solution [6]), "Yellow" string replacement (Substuite) is "Black" string. 2.2 SED Editor The format of the SED editing instruction is as follows: [Address1 [, address2]] function [argument] where the address parameter address1, address2 is the number of rows or regular expression strings, indicating the edited data line; function parameters Function [argument] is the editing action of the execution of the SED. The following two sections will carefully describe the representations of the location parameters and which function parameters are available. 2.2.1 Address parameters actually, the location parameter representation is only the data to be edited, replacing them with the number of rows or strings thereof. The following is a few examples (instructions are used as a function parameter d (refer to [section4.2]): Delete the 10th line of the file, the instruction is 10d. When you delete the information line containing the "Man" string, the instruction is / man / d. Delete the 10th line to 200 row of information in the file, the instruction is 10,200d. Deleting the 10th line of the file to the data line with the "Man" string, the instruction is 10, / man / d. Next, the representation of the order parameters in the order parameters, and the representation of the order parameters in the command (also as an example of the function parameter D). The content of the location parameters: Address is a 10-in number: This number represents the number of rows. When the instruction is executed, the editing action of the function parameter indicated by the data that meets the number of this row is executed. For example, delete the 15th line of data in the data file, the instruction is 15d (refer to [section4.2]). It is pushed, such as the MD data in the data file, the command is MD. Address to Regular Expression (Refer to [Appendix A]): When there is a string representing REGULAR EXPRESSION, the editing action indicated by the function parameter is executed.

In addition, "/" must be added before and after regone. For example, the instruction is /t.*T/d, indicating that all data lines containing two "T" letters. Among them, "." Indicates any font; "*" indicates that its preamble can be repeated, and they combine ". *" Represents any string between the two "T" letters. Number of adjacent parameters: In the instruction When there are two address parameters, such as address1, address2, indicate the editing of the data area, and address1 represents the starting information line, and the Address2 represents the Data Line. For the above, the following example is described. For example, the instruction is D which represents all the information lines within the file. For example, the instruction is 5D, which means the fifth line of the delete file. For example, the instruction is 1, / apple / d, which represents the delete data area, and has the data line of the "Apple" string in the first line in the file. For example, instructions are / Apple /, / Orange / D, which represents delete data zones, contains "Apple" strings in the file to data lines containing "Orange" strings 2.2.2 Some functions (function) Parameters lower page table This section describes the function parameters of all SEDs (refer to [Chapter 4]). Function parameters function: Label establishes the location of the Script File instructions. # Establish the solution {} set with instructions with the same address parameters. ! Do not perform function parameters. = Printing the number of data (LINE NUMBER). a Add the information entered by the user. b Label jumps to the executed instruction to the reference location established. c Substituting information entered by the user. D Delete information. D Delete the first newline letter before the Pattern Space. G copy information from Hold Space. G Add information from Hold Space to Pattern Space. H copy information from Pattern Space to Hold Space. H Add information from Pattern Space to Hold Space. l Printing the NonPrinting Character in the information with the ASCII code. i inserts the information line that adds the user input. N read into the next information. N Add the next information to Pattern Space. P Printing information. P Prints the information before the first newline letter in Pattern Space. Q jumps out of the SED editing. r read into its file content. s replace the string. T Label performs a replacement editing instruction. If replaced into cow P>, you skip the editing instruction to: Label is executed. W Write information to its file. X Exchange Hold Space and Pattern Space content. Y Transform Volume. Although the SED is only a function of the basic editing functions, the SED is made by the mating between the order parameters and the instructions in the command, and the SED will complete most of the editing tasks. 2.3 Employment instructions in the Perform file When the execution is too much, it is very confusing on the command column. At this time, these instructions can be organized in the file (such as the file name Script_File), with option -f script_file, then Let SED perform editing instructions in the Script_File. The lack of its command is as follows: SED -F script_file file files, where the order in which the Script_File internal editing instruction is executed is down. For example, an example of the previous section can be changed to the following command: SED -F YSB.SCR YEL.DAT where the YSB.SCR file is as follows: 1, 10DS / YELLOW / BLACK / G In addition, can be mixed on the command column Use options -E and -F, and the SED execution instruction sequence is still by the left to right of the command column, such as executing to the -f rear file, then executes. 2.4 Executing the editing of multiple file files On the SED command column, you can perform editing multiple file files at a time, they follow the editing instruction.

转载请注明原文地址:https://www.9cbs.com/read-117680.html

New Post(0)