sed:Stream EDitor,Line editor:
Usage: sed [option]…’script’inputfile…
Here we will first show the contents of /etc/fstab, which will be used later.
Common options:
- -n:Do not export contents from the pattern to the screen.
- -e:Multipoint editing
- -f:/PATH/TO/SCRIPT_FILE:Read the edit script from the specified file
- -r:Supports extended regular expressions
- -i:Original editor
Address delimit (in the following edit command bar, for example, screenshots):
- No address: processing the full text.
- Single address:
- #:Specified line
- /pattern/:Each row that can be matched by this pattern.
- Address range:
- #,#:How many lines to row?
- #,+#:The first few lines, there are a few lines.
- /pat1/,/pat2/:The first line that meets /pat1/ is /pat2/.
- #,/pat/:Which line do you want to go to?
Editor’s order:
- d:Delete. Here is an example:
- Delete the sixth row, as shown below. It is obvious that the sixth line has disappeared.
- Delete first to 3 rows.
- Delete the line at the beginning of UUID.
-
Delete from the first line, a total of 5 rows.
-
Delete the line from /etc to UUID.
-
Delete the row from seventh rows to UUID.
- Delete the sixth row, as shown below. It is obvious that the sixth line has disappeared.
- p:Display the contents in mode space:
- For example, display the first line of the UUID (where all schema space content is output, and then one more line of the UUID)
-
If you want to export only what we want, use the -n above.
- For example, display the first line of the UUID (where all schema space content is output, and then one more line of the UUID)
- a \text:Add text to the back of the row to support the use of \n to add multiple rows.
- For example, hello world! Is added to the row after /dev, and all the lines satisfying the condition are executed.
- i \text:Insert text in front of the row to support multi row insertion using \n.
- c \text:Substitution behavior single or multi line text
- w /path/to/somefile:Save the pattern space to match the row to the specified file.
- r /path/from/somefile:Reads the text flow from the specified file to the row that matches the row in the pattern space.
- =:Print line numbers for rows in schema space
- !:Reverse condition
- s///:Support for using other delimiters, s@@@, s###
- Replacement mark: G: in line global replacement. P: displays the row that succeeded.