Grep für Windows - Beispiel für findstr

Grep für Windows - Beispiel findstr

linux-logo

Ich liebe den Befehlgrepunter Linux, er hat geholfen, Zeichenfolgen einfach zu suchen und zu filtern, mich immer zu fragen, was das entsprechende Tool unter Windows ist, und diesenfindstr kürzlich gefunden.

In diesem Artikel werde ich einige meiner bevorzugten "grep" -Beispiele unter Linux vorstellen und erläutern, wie man sie mit dem Befehl "findstr" auf Windows portiert.

1. Filtern Sie ein Ergebnis

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. Suchen Sie eine Datei

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. Durchsuchen Sie eine Liste von Dateien

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 = Nur Name der Dateien drucken, die Übereinstimmungen enthalten.

4. Help

4.1 The most powerful command ~

#Linux
$ grep --help
$ man grep

#Windows
c:\> findstr -?

Note
Haben Sie andere Beispiele? Teilt es unten, danke.

Related