Home > System Tutorial > LINUX > body text

Use command to view partial lines of log file in Linux

WBOY
Release: 2024-01-01 22:05:56
forward
704 people have browsed it

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

are displayed

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

【二】Display lines 1000 to 3000

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

*Note the order of the two methods

break down:

tail -n 1000: Display the last 1000 lines
tail -n 1000: Start displaying from line 1000, and display
after line 1000 Head -n 1000: Display the first 1000 lines

【三】Use sed command

sed -n '5,10p' filename This way you can only view lines 5 to 10 of the file.

Linux statistics file line number

Syntax: wc [options] file...

Description: This command counts the number of bytes, words, and lines in a given file. If no filename is given, then standard input is read. wc also gives a total count of all specified files. Words are the largest string of characters separated by space characters.

The meaning of each option of this command is as follows:

 -c counts the number of bytes.
- l counts the number of rows.
- w counts the number of words.

These options can be used in combination.

The order and number of output columns are not affected by the order and number of options.

Always displayed in the following order and with a maximum of one column per item.
Number of lines, number of words, number of bytes, file name
If there is no filename on the command line, the filename does not appear in the output.

For example:

$ wc - lcw file1 file2
4 33 file1
7 52 file2
11 11 85 total

Example analysis:

1. Statistics of the number of js files in the demo directory:
find demo/ -name "*.js" |wc -l
2. Count the code lines of all js files in the demo directory:
find demo/ -name "*.js" |xargs cat|wc -l or wc -l `find ./ -name "*.js"`|tail -n1
3. Count the code lines of all js files in the demo directory, and filter out empty lines:
find /demo -name "*.js" |xargs cat|grep -v ^$|wc -l

The above is the detailed content of Use command to view partial lines of log file in Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:jb51.net
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!