Click to view the original blog.
sed
is the abbreviation for Stream editor, which is a non-interactive stream editor for filtering or converting text.
Not to be continued ...
Profile
Sed Options ... Script [Input File ...]
Describe
sed
The editor is called the Stream editor, which is the opposite of the normal interactive text editor. In an interactive text editor, such as VIM, you can use keyboard commands to interactively insert, delete, or replace text in your data. The stream editor edits the data flow based on a pre-supplied set of rules before the editor processes the data.
sed
The editor can process data in the data flow according to commands, which are either entered from the command line or stored in a command text file. The SED editor performs the following actions.
(1) reads one row of data from the input at a time.
(2) match the data according to the provided editor commands.
(3) Follow the commands to modify the data in the stream.
(4) Output the new data to the STDOUT. After the flow editor matches all the commands to a row of data, it reads the next row of data and repeats the process. When the stream editor finishes processing all the data rows in the stream, it terminates. Because the commands are given sequentially by line, the SED editor can complete the editing operation by simply processing the data stream over and over.
This makes the SED editor much faster than the interactive editor, and you can quickly complete automatic changes to the data.
Understand
This command is somewhat complex and complex, and requires a gradual digestion as it is powerful.
Common use Cases
The instance replaces all "Hello" in the Input.txt file with "world" and outputs it to output.txt.
sed ‘s/hello/world/‘ input.txt > output.txt
This is probably the most commonly used example (at least in my experience of working for so many years), sed
the commands used here s
. If you want to export to the original file, use -i
parameters.
sed -i ‘s/hello/world/‘ input.txt
This will behave differently under Mac, refer to: 49495885.
Reference: Https://www.gnu.org/software/sed/manual/sed.html.
Shell command usage and common use cases under Linux: SED