I'm wondering if there is a simple way to transform a grep
command such as
grep -c -f regex.txt file.txt
to return the total number of matched lines in file.txt
for each line of regex.txt
, instead of the sum of the matched lines found for all patterns in regex.txt
as the above command does.
My current method of handling this is to use xargs
(or GNU parallel
interchangeably):
cat regex.txt | xargs -I{} grep -c {} file.txt
Can grep
do this in one fell swoop?
答案 0 :(得分:1)
grep -o -f regex.txt | sort | uniq -c