The grep command argument list is too long? We have find, Xargs, and grep.

Source: Internet
Author: User
Tags egrep

First, the problem of the current directory in the specified sub-directory specified in the server for the specified time range of all containing "meritorious acquisition" of the log content 1, the specified subdirectory 1.2.3.25 .... 1.2.3.83
2, specify the server the server's log file name format is: Sceneserver.log. (the latter two digits of the year, two digits) (month, not enough with 0 complement, two digits) (Day, not enough with 0 complement, two digits)-(hours, not enough with 0 complement, two digits)
For example, January 22, 2014 16 o'clock, the log file name is: sceneserver.log.140122-163, the specified time range from October 2014 to 22-2014 December 9

Second, grep's helplessness undoubtedly, directly think of is certainly powerful grep, write command:
grep ' exploits get ' 1.2.3. {2[5-9],[3-7][0-9],8[0-3]}/sceneserver.log.14{10{2[2-9],3},11,120[1-9]}* > Tmp.log

The results will come out. Tips:
Hint: command argument list is too long
(The matching files were found to be close to 3w later)
Okay, so here's the question: besides grep, what are the Linux commands that support regular expression search files?

Three, a strong combination to find the file is definitely the Find command, man, found that find is actually supporting the regular expression. Command:
Find. -regextype "Egrep"-regex "\./1\.2\.3\. (2[5-9]| [3-7] [0-9]|8[0-3])/sceneserver\.log\.14 (2[2-9]|3) |11|120[1-9]). *-print0 | xargs-0 grep ' meritorious acquisition ' >> Tmp.log
Note that there are: 1. Note the difference between-print and-print0 in the Find command parameter, and the difference between the Xargs parameter and the 0 parameter and no-0 parameter 2, you can use the following command to view the number of matching files
Find. -regextype "Egrep"-regex "\./1\.2\.3\. (2[5-9]| [3-7] [0-9]|8[0-3])/sceneserver\.log\.14 (2[2-9]|3) |11|120[1-9]). *-print | Wc-l




The grep command argument list is too long? We have find, Xargs, and grep.

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.