Today, in the course of learning Linux, we discovered the SED directive.
First, the full name of the SED is: Stream Editor
There are two forms of calling the SED command:
sed [options] ' command ' file (s)
sed [options]-F scriptfile file (s)
Today, I'll talk about the use of the-i parameter in the SED command.
-I refers to changes in the current text
Specific content can be used in Linux
Mans SED
To view
But if it is the following code, will be error, can not achieve the function I want
Sed-i ' 2,4d ' example.txt
The above code I want to implement delete Example.txt in the 2,3,4 line
Since-I is required and must have a string to back up the source file, and the string will be appended to the source filename to form the backup file name.
So
The correct method is as follows:
Sed-i "" ' 2,4d ' example.txt
So since. We can do what we want.
If you do not want to use the-I parameter, we can also use another method:
Sed ' 2,4d ' example.txt > ANOTHER_EXAMPLE.TXTMV another_example.txt example.txt
OK ~ This is my little harvest. A little harvest a day by a pig
How to use the Sed-i command under MAC