From df4551468a39904e48df5ed49ef4b3d7b257da2b Mon Sep 17 00:00:00 2001 From: Michael Diamond Date: Thu, 23 Apr 2020 11:52:23 -0700 Subject: [PATCH] Add advice for multiple files - https://github.com/koalaman/shellcheck/issues/1920 --- SC2126.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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`.