Sunday, June 5, 2022

[SOLVED] Shell script grep command -c (count) -- does command-line ordering matter?

Issue

just a quick question regarding a doubt. What's the difference between these two:

grep "$genre" "$i" | grep "$type" -c

and

grep "$genre" "$i" | grep -c "$type"

Do they do perhaps the same thing?


Solution

As you can see from man grep, the -c switch belongs to the so-called "General Output Control". Those switches can be placed on different places in the grep ... command and this has no impact on the general outcome, so indeed, both lines you mention are equal.



Answered By - Dominique
Answer Checked By - Senaida (WPSolving Volunteer)