Search for a string in a large file in CentOS

Source: Internet
Author: User

Search for a string in a large file in CentOS

Today, I found that there is a data record in the database that is not quite correct. to query how the value of this data is updated to the present step by step, I need to query the mysql Log, but because the log file is too large, therefore, direct search consumes a lot of time and system resources. Therefore, the log file is cut and then searched in the cut file, which greatly improves the efficiency.

Step 1:

Cp mysql. log/tmp/logSearch/mysqlOldLog, copy the old log file and operate the new file. This will not affect the operation of the original data and database.

Step 2:

Split-a 3-d-B 10 m mysqlOldLog splitLog

Use the split command to cut the backup log file. Parameter-a indicates that the suffix length is 3, and-d indicates that the suffix is represented by numbers, -B 10 M indicates that the size of each file is 10 M (except for the last file), and the cut file is like

Splitlog0000, splitlog0001, splitlog0002 and so on

Step 3:

Find. | xargs grep-ril "UPDATE \'t _ user"

This command will search for all the files in the current folder and find the files containing "UPDATE 't_user" to list the names of the files,

Here, a backslash is used for escape, which is essential. Otherwise, the system will think that the following command will return an error.

After listing the files, you can find a few objects in a targeted manner, which greatly improves the efficiency ..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.