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 to view the lines of a file in linux

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

Share

Shulou(Shulou.com)06/03 Report--

With the development of the Internet, more and more people have entered the IT industry, so how to view the first few lines of the file in Linux? You know what? In order to let everyone know more about Linux system, Xiaobian summarized the following contents for everyone, and looked down together.

How linux displays certain lines (middle lines) of a file

[1] Starting from line 3000, display line 1000. 3000 to 3999 lines are displayed.

cat filename | tail -n +3000 | head -n 1000

Show 1000 to 3000 lines

cat filename| head -n 3000 | tail -n +1000

Note the order of the two methods.

Decomposition:

tail -n 1000: Display the last 1000 lines

tail -n +1000: Display from 1000 lines, display after 1000 lines

head -n 1000: Display the first 1000 lines

Use the SED command.

sed -n '5,10p' filename

This way you can view only lines 5 to 10 of the file.

Use the grep command.

grep -C 5 foo filename Displays the line matching the foo string in the file and the top and bottom 5 lines

grep -B 5 foo filename Display foo and the first 5 lines

grep -A 5 foo filename Display foo and the next 5 lines

The above is how to view the details of the first few lines of the file in linux. Is there any harvest after reading it? If you want to know more, welcome to the industry information!

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