Sed-I command details, sed-I
Sed-I command details
[Root @ www ~] # Sed [-nefr] [action] Option and parameter:-n: Quiet Mode. In general sed usage, all data from STDIN is usually listed on the terminal. However, if the-n parameter is added, only the row (or action) that has been specially processed by sed will be listed. -E: directly edit the sed action in the Command column mode.-f: Write the sed action in a file.-f filename can run the sed action in filename; -r: sed supports the syntax of extended regular notation. (The default is the basic regular expression syntax)-I: directly modify the content of the file to be read, rather than output to the terminal. Action Description: [n1 [, n2] functionn1, n2: does not necessarily exist. Generally, it indicates "number of rows selected for action". For example, if my actions need to be performed between 10 and 20 rows, then "10, 20 [Action Behavior]" function: a: new, and a can be followed by a string, these strings will appear in the new line (the current next line )~ C: replace. c can be followed by strings. These strings can replace rows between n1 and n2! D: delete, because it is delete, so d is usually not followed by any comment; I: insert, I can be followed by a string, these strings will appear in the new line (the previous line currently); p: print, or print the selected data. Generally, p runs with the sed-n parameter ~ S: replace, you can directly replace the work! Generally, this s action can be combined with regular notation! For example, 1, 20 s/old/new/g!
Sed-I directly operates on text files
Sed-I's/original string/New String/'/home/1.txt sed-I's/original string/New String/G'/home/1.txt
The difference between the two commands is, let's look at the example.
This is 1.txt content
#cat 1.txtdddd#ff
Let's look at the difference between the two commands.
Sed-I's/d/7523/'/home/1.txt execution result 75237523dd # ffsed-I's/d/7523/G'/home/1.txt execution result 7523752375237523 # ff
Remove the initial @ with @ at the beginning of the line @
sed -i 's/^@//' file
Insert a new row before a specific string
Sed-I '/specific string/I new line string' file
Insert a new line after the row of a specific string
Sed-I '/specific string/a new line string' file
Delete a specific string
Sed-I '/string/d' file