grep 'saved\|retrieved' ./*/wget*log* | wc -l
^-- SC2126: Consider using grep -c instead of grep|wc -l.
Currently, I want to grep multiple files for the matching string and print the matching line, then count it.
Using suggested solution gives individual file count.
grep -c 'saved\|retrieved' ./*/wget*log*
./wget-log:0
./wget-log.1:1
./wget-log:2:1
./wget-log.3:1
Using my command.
grep 'saved\|retrieved' ./*/wget*log* | wc -l
3
When considered the warning put a ignore directive in and continue on.
That's how I treat these messages. It's hard to know what your intentions are.
You can avoid running wc and use only grep and some bash magics, but it's a bit cryptic:
echo $(($(c=($(grep -hc 'saved\|retrieved' ./*/wget*log*)); IFS=+; echo "${c[*]}")))
@brother Yeah, i did that.
Also, i think it's not that hard to know my intentions as this is only a problem for globs, check could be added in source.
Again, just a thought, this isn't something important.
@mnuccioarpae Well, bash magics are good, cryptic or not.
Thank you for the help.
No need for all that "bash magic", just pipe the contents into grep:
cat ./*/wget*log* | grep -c 'saved\|retrieved'
Updated the Wiki entry.
Most helpful comment
No need for all that "bash magic", just pipe the contents into
grep:Updated the Wiki entry.