Filtering text using Grep's PowerShell

Source: Internet
Author: User

Filtering text using Grep's PowerShell

There is a log file, about 4M in size, asking to find a record that takes more than 100s. First think of the powerful grep, then get up.
First find information on the Internet, this article, there are several ways:

The first type:
Get-content somefile.txt|findstr "Someregexp"
Get-content can be replaced by Cat,powershell already gave them an alias, but really considerate sheller.
This approach is a mix of commandline and PowerShell, because Findstr is a command-line tool and not a PowerShell cmdlet.
The second type:
Cat Somefile.txt | where {$
-match "Some_regexp"}
Purebred PowerShell is implemented using the where filter
The third type:
Select-string "Some_regexp" Somefile.txt
Directly with the implementation of select-string.

After testing, the last PowerShell command written is as follows:

Cat " \d{3,}\.\d{2,}s "} >>result.log

Use where this, this can use regular, findstr command not. Inside the regular match string "\d{3,}.\d{2,}s" is also very simple , "3 numbers. 2 digits above S" means.

Finally: Filter out the results into Result.log

17:05:14,884 [email protected] HTTP-0.0.0.0-8888-PROCESSOR7 DEBUG strategyactionhelper:-Getstrategyinvoicemap Finished ... Consumed time:191.028s
17:05:14,889 [email protected] Http-0.0.0.0-8888-processor4 DEBUG strategyactionhelper:-Getstrategyinvoicemap Finished ... Consumed time:191.04s
17:07:19,112 [email protected] HTTP-0.0.0.0-8888-PROCESSOR7 DEBUG strategyactionhelper:-setliststrategyattributes Finished ... Consumed time:379.082s
17:07:20,106 [email protected] Http-0.0.0.0-8888-processor4 DEBUG strategyactionhelper:-setliststrategyattributes Finished ... Consumed time:381.021s
17:07:37,449 [email protected] Http-0.0.0.0-8888-processor4 DEBUG strategysearchaction:-setliststrategyattributes Finished ... Consumed time:398.364s
17:25:26,773 [email protected] Http-0.0.0.0-8888-processor4 DEBUG CL:-Build table data in Getclientcontractelement Finis Hed ... Consumed time:1064.296s
17:25:27,328 [email protected] Http-0.0.0.0-8888-processor4 DEBUG CL:-Getclientcontractelement finished ... Consumed time:1064.858s
17:25:27,328 [email protected] Http-0.0.0.0-8888-processor4 DEBUG CL:-Buildgtreport finished ... Consumed time:1064.87s free memory:176198

Note: The code in PowerShell is GB K, not UTF8, if you want to filter Chinese characters, the simple way is to first convert the UTF8 encoded file to ANSI encoding.

Filtering text using Grep's PowerShell

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.