Sed is a stream editor, the stream editor will edit the data stream based on a set of rules provided in advance before the editor processes the data.
The sed editor can process the data in the data stream according to commands, which are either input from the command line or stored in a command text file. The workflow of sed The workflow of sed mainly includes three processes of reading, executing and displaying:
Read: sed reads a line of content from the input stream (file, pipe, standard input) and stores it in a temporary buffer (also known as pattern space).
Execution: By default, all sed commands are executed sequentially in the pattern space. Unless the address of the line is specified, the sed command will be executed sequentially on all lines.
Display: Send the modified content to the output stream. After sending the data, the pattern space will be cleared. Before all file contents are processed, the above process will be repeated until all contents are processed. Before all file contents are processed, the above process will be repeated until all contents are processed. Note: By default, all sed commands are executed in the pattern space, so the input file will not change in any way, unless redirection is used to store the output.
Command format:
sed -e'操作'文件1文件2 ...
sed -n -e'操作'文件1文件2 ...
sed -f 脚本文件 文件1 文件2 ...
sed -e '操作'文件1 文件2 ...
sed -e 'n {
操作1
操作2
...
}' 文件1 文件2 ...