Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

One of the linux commands commonly used during testing [delete the specified file line]

Shulou Source: shulou.com Published: 2022-06-03 06:28:52 11月23日 Update

I. demand

During the test, you will encounter the situation of deleting the specified file lines, such as deleting useless information in the configuration file.

For example, if you have the following file, delete the last 3 lines.

II. Solutions

1. We know the line number.

Sed-I'21 female 23 Testfile.log

two。 We know the keywords.

Grep-n 'deleted' Testfile.log # get the line number sed-I' 21 Magi 23 Testfile.log first.

3. Use the vi command

Find the line you want to delete and type d3D in command mode to delete it.

Vi dd can be deleted line by line, d (ymurx) d can delete paragraph lines

Tags: File command line number procedure test information key keyword situation method pattern paragraph requirement configuration commonly used Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi MySQL vpn Shulou Information macOS