diff --git a/SC2126.md b/SC2126.md index c2cd838..ea31897 100644 --- a/SC2126.md +++ b/SC2126.md @@ -12,6 +12,20 @@ grep foo | wc -l grep -c foo ``` +#### For multiple files + +Instead of: + +```sh +grep foo *.log | wc -l +``` + +Pipe all the file contents into `grep` (passing the files directly to `grep` causes `-c` to print each file's count separately, rather than the total): + +```sh +cat *.log | grep foo -c +``` + ### Rationale: This is purely a stylistic issue. `grep` can count lines without piping to `wc`.