Home > Operation and Maintenance > Linux Operation and Maintenance > How to check the line number to line number of a file in Linux

How to check the line number to line number of a file in Linux

王林
Release: 2020-03-12 15:33:25
Original
11856 people have browsed it

How to check the line number to line number of a file in Linux

linux How to display certain lines of a file (the middle lines)

[1] Starting from line 3000, display 1000 lines. That is, display lines 3000~3999

cat filename | tail -n +3000 | head -n 1000
Copy after login

[2] Display lines 1000 to 3000

cat filename| head -n 3000 | tail -n +1000
Copy after login

(recommended tutorial: linux tutorial)

Pay attention to the order of the two methods.

Decomposition:

tail -n 1000: display the last 1000 lines

tail -n 1000: start displaying from line 1000, and display the following

head -n 1000: Display the first 1000 lines

[3] Use the sed command

sed -n ‘5,10p’ filename
Copy after login

so that you can only view the 5th to 10th lines of the file.

[Four] Use grep command

grep -C 5 foo filename Display the line matching the foo string in the file file and the 5 lines above and below

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

grep -A 5 foo filename displays foo and the last 5 lines

Recommended related video tutorials: linux video tutorial

The above is the detailed content of How to check the line number to line number of a file in Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template