linux operation of log files

How does Linux  display certain lines of a file (the middle lines)

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

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

[2] Display 1000 lines to 3000 lines

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

*Note the order of the two methods

break down:

    tail -n 1000: show last 1000 lines

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

    head -n 1000: display the first 1000 lines

[3] Use the sed command

 sed -n '5,10p' filename so you can only look at lines 5 to 10 of the file.

Linux statistics file line count

Syntax: wc [options] file...

Description: This command counts the number of bytes, words and lines in a given file. If no filename is given, it is read from standard input. wc also gives the presidential count for all specified files. A word is the largest string separated by space characters.

The meanings of the options of this command are as follows:

  -c count bytes.

  - l Count the number of lines.

  - w counts 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 display in the order described below with at most one column per item.

Lines, Words, Bytes, Filename

If there is no filename on the command line, the filename does not appear in the output.

E.g:

$ wc - lcw file1 file2

4 33 file1

7 52 file2

11 11 85 total

Example analysis:

1. Count the number of js files in the demo directory:

find demo/ -name "*.js" |wc -l

2. Count the number of lines of code in all js files in the demo directory:

find demo/ -name "*.js" |xargs cat|wc -l 或 wc -l `find ./ -name "*.js"`|tail -n1

3. Count the number of lines of code in all js files in the demo directory, and filter out blank lines:

find /demo -name "*.js" |xargs cat|grep -v ^$|wc -l

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326486430&siteId=291194637