Grep for Windows - findstrの例

Grep for Windows – findstrの例

linux-logo

Linuxのgrepコマンドが大好きです。文字列の検索とフィルタリングを簡単に行うことができ、Windowsの同等のツールは何であるかを常に考え、最近このfindstrを見つけました。

この記事では、Linuxでのお気に入りの「grep」の例と、「findstr」コマンドを使用してWindowsに「移植」する方法を紹介します。

1. 結果をフィルタリングする

1.1 Classic example to filter a listing result.

#Linux
$ ls -ls | grep example

#Windows
c:\> dir | findstr example

1.2 Add ignore case, and filter the listing result with multiple strings.

#Linux - Need '-E' option and Uses "|" to separate multiple search strings.
$ ls -ls | grep -iE "example|music"

#Windows - Use spaces to separate multiple search strings
c:\> dir | findstr -i "example music"

2. ファイルを検索する

2.1 Search matched string in a file.

#Linux
$ grep example test.txt

#Windows
c:\> findstr example test.txt

2.2 Counting the number of matches.

#Linux
$ grep -c example test.txt

#Windows - Piped with find /c command.
c:\> findstr -N "example" test.txt | find /c ":"

3. ファイルのリストを検索する

3.1 Search matched string in a list of files.

#Linux
$ grep example -lr /path/folder

#Windows
c:\> findstr /M example c:\folder\*

*(grep)-l、(findstr)/ M =一致するファイルの名前のみを出力します。

4. Help

4.1 The most powerful command ~

#Linux
$ grep --help
$ man grep

#Windows
c:\> findstr -?

Note
他に例はありますか? 以下で共有します、ありがとう。

Related