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 ..