Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does linux view certain lines of a file

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains the "linux how to view some lines of the file", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "linux how to view a few lines of the file" bar!

Linux to view a few lines of the file method: 1, use the sed command, syntax "sed-n'X Yp' file name", you can view the contents of the file line X to Y; 2, with cat, tail and head commands, syntax "cat file name | tail-n + X | head-n Y".

The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

The method of viewing certain lines of a file by linux

Method 1: use the sed command

Sed-n'X Yp' filename

You can view lines x to Y of the file.

For example: display file lines 31 to 45

Sed-n'31 450p 'requirements.txt

Method 2: use the cat, tail, and head commands

The cat command can be used to display the contents of a text file

The tail command outputs the last part of the file to a standard device with the specified parameters

The head command displays the beginning of the file to the standard output

Combine the three commands to view lines x to Y of the file.

Syntax format 1: start at line X and display line Y. That is, the line X~ (Ymur1) is displayed.

Cat filename | tail-n + X | head-n Y

Example: start at line 3000 and display 1000 lines; that is, display 3000mm 3999 lines

Cat requirements.txt | tail-n + 3000 | head-n 1000

Syntax format 2: display lines X to Y

Cat filename | head-n X | tail-n + Y

Example: display lines 1000 to 3000

Cat requirements.txt | head-n 3000 | tail-n + 1000

* Note the order of the two methods

Decompose:

Tail-n 1000: displays the last 1000 lines

Tail-n + 1000: displays from line 1000 and after line 1000

Head-n 1000: displays the first 1000 lines

Thank you for your reading, the above is the content of "linux how to view certain lines of the document", after the study of this article, I believe you have a deeper understanding of how to view a few lines of the linux file, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report