Lọc, tìm kiếm chuỗi | String filtering, searching [P.1]

Windows:

i. Tìm kiếm bằng ‘findstr’ trong windows (tested: windows 10 commandline):

dir e: /a/s | findstr /R /i “Directory File”

<tìm kiếm dòng nào có từ “Directory” hay “File”>: /i

out-put:

……..

Directory of E:\Adobe Phtoshop CC 2015\Photoshop CC 2015 v16\Photoshop_16_LS20_win64\Adobe CC 2015\Deployment
 27 File(s) 17,766 bytes
 Directory of E:\Adobe Phtoshop CC 2015\Photoshop CC 2015 v16\Photoshop_16_LS20_win64\Adobe CC 2015\packages
 2 File(s) 9,849 bytes
 Directory of E:\Adobe Phtoshop CC 2015\Photoshop CC 2015 v16\Photoshop_16_LS20_win64\Adobe CC 2015\packages\CCM
 3 File(s) 5,856,779 bytes
 Directory of E:\Adobe Phtoshop CC 2015\Photoshop CC 2015 v16\Photoshop_16_LS20_win64\Adobe CC 2015\packages\core
 3 File(s) 13,641,746 bytes

……..

ii. findstr cũng cho phép tìm kiếm theo cú pháp regular expression, với option /R, khi đó findstr xem chuỗi cần tìm như một reg. expression

findstr /R /C:”regular expression here

Regular expression quick reference:
. Wildcard: any character
* Repeat: zero or more occurrences of previous character or class
^ Line position: beginning of line
$ Line position: end of line
[class] Character class: any one character in set
[^class] Inverse class: any one character not in set
[x-y] Range: any characters within the specified range
\x Escape: literal use of metacharacter x
\<xyz Word position: beginning of word
xyz\> Word position: end of word

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s