First, the demand
During the test, you will encounter cases where the specified file rows are deleted, such as removing useless information from the configuration file.
For example, the following file, to delete the last 3 lines.
650) this.width=650; "src=" Https://s5.51cto.com/oss/201711/06/31cb96437834aa557f0f8ce18e3f55be.png "title=" File1.png "alt=" 31cb96437834aa557f0f8ce18e3f55be.png "/>
Second, the solution
1. We know the line number
Sed-i ' 21,23 ' d Testfile.log
2. We know the keyword
Grep-n ' deleted ' Testfile.log #先获取行号sed-i ' 21,23 ' d Testfile.log
650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/06/e6d7c2d3d887609e7688145b89e98598.png-wh_500x0-wm_3 -wmp_4-s_838541374.png "title=" grepsed (2). png "alt=" E6d7c2d3d887609e7688145b89e98598.png-wh_ "/>
3. Use the VI command
Locate the row you want to delete, and in command mode, type D3D to delete.
VI DD can be deleted line by row, D (y-x) d can delete paragraph lines
This article is from the "Le Gakuen" blog, please be sure to keep this source http://2338053.blog.51cto.com/2328053/1979209
"Delete a specified file line" from a common Linux command during testing