How to read the last few lines in cat in linux

WBOY
Release: 2022-07-19 17:18:11
Original
16219 people have browsed it

In Linux, you can use the cat command with the tail command to view the last few lines of the file; the cat command is used to connect files and print to the standard output device, and the tail command can be used to view the contents of the file. When tail When the parameter of the command is set to "-n", the contents of the specified lines at the end of the file can be displayed. The syntax is "cat specified file | tail -n displays the number of the last few lines".

How to read the last few lines in cat in linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to read the last few lines of cat in Linux

The cat (full English spelling: concatenate) command is used to connect files and print to the standard output device.

Syntax format

cat [-AbeEnstTuv] [--help] [--version] fileName
Copy after login

Parameter description:

  • -n or --number: Number all output lines starting from 1 .

  • -b or --number-nonblank: Similar to -n, except that blank lines are not numbered.

  • -s or --squeeze-blank: When encountering more than two consecutive blank lines, replace them with one blank line.

  • -v or --show-nonprinting: Use the ^ and M- symbols except LFD and TAB.

  • -E or --show-ends : Show $ at the end of each line.

  • -T or --show-tabs: Display TAB characters as ^I.

  • -A, --show-all: Equivalent to -vET.

  • -e: Equivalent to the "-vE" option;

  • -t: Equivalent to the "-vT" option;

tail command can be used to view the contents of the file,

Command format:

tail [参数] [文件]
Copy after login

Parameters:

  • -f Loop reading

  • -q Do not display processing information

  • -v Display detailed processing information

  • -c The number of bytes displayed

  • ##-n Display the last n lines of the file

The example is as follows

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

Syntax format 1: Starting from line X, display line Y. That is, display the Y row

cat filename | tail -n +X | head -n Y
Copy after login

Example: Display rows 1000 to 3000

cat requirements.txt | tail -n +3000 | head -n 1000
Copy after login
*Note 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

  • Recommended learning:

    Linux video tutorial

The above is the detailed content of How to read the last few lines in cat 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
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!