Sed:stream Editor, line editors:
Usage: sed [option] ... ' Script ' Inputfile ...
This shows the contents of the/etc/fstab, which will be used later
Common options:
- -N: Do not output the contents of the mode to the screen
- -e: Multi-point editing
- -f:/path/to/script_file: Reading the edit script from the specified file
- -R: Supports the use of extended regular expressions
- -I: In situ editing
Address delimitation (Edit command bar below for an example):
- Do not give address: the full text of the processing
- Single Address:
- #: The specified row
- /pattern/: Each row to which the pattern can be matched
- Address range:
- #,#: First line to first line
- #,+#: First few lines, a few lines
- /pat1/,/pat2/: First occurrence of rows to/pat2/that meet/pat1/
- #,/pat/: Which line is the first few lines
Edit command:
- D: Delete. The following examples illustrate:
- Delete line 6th, for example, clearly see line sixth disappears
- Delete Line 1th to 3rd
- Delete the beginning of the UUID line
Delete starts from the first line, altogether 5 lines
Delete from #/etc this line to the beginning of the UUID line
Delete the line from line 7th to the beginning of the UUID
- P: Displays the contents of the mode space:
- A \text: Append text after line, support multi-row append using \ n
- For example, add Hello World after the/dev line, and all rows that meet the criteria are executed
- I \text: inserting text in front of the line, enabling multi-row insertion using \ n (same as previous effect)
- C \text: Replacing a line of behavior or multiple lines of text
- W/path/to/somefile: Save the pattern space to match the line to the specified file
- R/path/from/somefile: Reads the text of the specified file after the line that matches the line in the pattern space
- =: Prints line numbers for lines in pattern space
- ! : Take the reverse condition
- s///: Supports the use of other separators, [email protected]@@,s###
- Replace tag: g: inline global substitution. P: Displays the row where the replacement was successful.
Introduction to SED commands for Linux