Home > Operation and Maintenance > Linux Operation and Maintenance > How to delete the first few lines of a file in Linux

How to delete the first few lines of a file in Linux

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2022-03-21 10:50:53
Original
12110 people have browsed it

In Linux, you can use the sed command to delete the first few lines of a file. This command can process and edit text files according to the instructions of the script. It can be used with regular expressions to achieve the effect of deleting the first few lines of the file. Syntax It is "sed -i '1, number of first few lines d' file name".

How to delete the first few lines of a file in Linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to delete the first few lines of a file in Linux

sed -i '1,nd' 文件名
这个是删除第一行到第n行
Copy after login

sed is a stream editor. It is a very good tool for text processing. It can be used perfectly with regular expressions and has extraordinary functions. . During processing, the currently processed line is stored in a temporary buffer, called "pattern space", and then the sed command is used to process the contents of the buffer. After the processing is completed, the contents of the buffer are sent to the screen. Then process the next line, and repeat until the end of the file. The file contents are not changed unless you use redirection to store the output.

Sed is mainly used to automatically edit one or more files. It can perform specific tasks such as replacing, deleting, adding, and selecting data lines, simplifying repeated operations on files, writing conversion programs, etc.

Syntax

sed [-hnV][-e<script>][-f<script文件>][文本文件]
Copy after login

Parameter description:

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template