Grep for Windows – findstrの例
私はLinuxで `grep`コマンドが大好きです。文字列を簡単に検索してフィルタリングするのに役立ちました。Windowsでこれと同等のツールが何であるか疑問に思っていました。
この記事では、私が好きなgrepのいくつかの例をLinux上で共有し、findstrコマンドでWindowsに “移植”する方法を説明します。
1.結果をフィルタリングする
1.1リストの結果をフィルタリングするための古典的な例。
#Linux $ ls -ls | grep mkyong #Windows c:\> dir | findstr mkyong
1.2大文字小文字を無視して追加し、複数の文字列でリストの結果をフィルタリングします。
#Linux - Need '-E' option and Uses "|" to separate multiple search strings. $ ls -ls | grep -iE "mkyong|music" #Windows - Use spaces to separate multiple search strings c:\> dir | findstr -i "mkyong music"
2.ファイルを検索する
2.1ファイル内で一致する文字列を検索します。
#Linux $ grep mkyong test.txt #Windows c:\> findstr mkyong test.txt
2.2マッチの数を数える。
#Linux $ grep -c mkyong test.txt #Windows - Piped with find/c command. c:\> findstr -N "mkyong" test.txt | find/c ":"
3.ファイルのリストを検索する
3.1ファイルのリストで一致する文字列を検索します。
#Linux $ grep mkyong -lr/path/folder #Windows c:\> findstr/M mkyong c:\folder\**
** (grep) -l , (findstr)/M = print only name of files containing
matches.
4. Help
4.1 The most powerful command ~
#Linux $ grep --help $ man grep #Windows c:\> findstr - ?