How to find the specified content of a large file in Linux

How to find the specified content of a large file in Linux

Think big and small, then redirect.

Sometimes Linux encounters very large files, and keyword searches must exceed the entire screen, making it impossible to view all the content. For example, if we want to view all logs of a certain string in a very large log file info.log, we can use cat info.log | grep '1711178968'. If too much is displayed, we can add time and line control. You can also use the '>>' command. cat info.log | grep '1711178968' >> temp.log Temporarily save the intermediate results and view the temp.log file page by page using tools such as more and less

If the log is within a certain time range, you can still intercept the log based on time:

// Capture the logs for a certain period of time sed -n '/2018-10-25 17:30:41/,/2018-10-25 21:47:02/p' root.2018-10-25.log > update.log

In the log on the 25th, extract the logs between 17:30 and 21:47.

Use the more command to view.

Then search with /${keyword}, ​​for example /1711178968, n for the next item, b for the previous item

The above method of implementing how to search for specified content in large files in Linux is all I have to share with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • How to Find the Top 10 Largest Files in Linux
  • How to find large directories and large files in Linux (recommended)
  • Linux searches for files containing specified text (linux searches for specified files)

<<:  The correct way to use MySQL indexes and detailed explanation of index principles

>>:  How to Develop a Progressive Web App (PWA)

Recommend

Summary of frequently used commands for Linux file operations

0. New operation: mkdir abc #Create a new folder ...

CSS implements 0.5px lines to solve mobile compatibility issues (recommended)

【content】: 1. Use background-image gradient style...

CSS achieves the effect of aligning multiple elements at both ends in a box

The arrangement layout of aligning the two ends o...

Basic operations on invisible columns in MySQL 8.0

Table of contents 01 Create invisible columns 02 ...

Experience in solving tomcat memory overflow problem

Some time ago, I submitted a product version to t...

Analysis of the Neglected DOCTYPE Description

doctype is one of them: <!DOCTYPE HTML PUBLIC &...

Setting up shadowsocks+polipo global proxy in Linux environment

1. Install shadowsocks sudo apt-get install pytho...

JavaScript to achieve drop-down menu effect

Use Javascript to implement a drop-down menu for ...

Graphic tutorial for installing MySQL 5.6.35 on Windows 10 64-bit

1. Download MySQL Community Server 5.6.35 Downloa...

The connection between JavaScript and TypeScript

Table of contents 1. What is JavaScript? 2. What ...

Three ways to draw a heart shape with CSS

Below, we introduce three ways to draw heart shap...

Using JS to implement a rotating Christmas tree in HTML

<!DOCTYPE HEML PUBLIC> <html> <hea...

jQuery implements simple button color change

In HTML and CSS, we want to set the color of a bu...