File A is the file I have to search through. File B is the File, that has what I need to search in file A.
File A is a lot of code, simular to this:
test test
a = rr
b = gg
test test
c = a + b
test
Those variables are sometimes only declared, and not used, and I filtered all variables, that I need out, into File B:
a
b
I want to count how often each variable (each variable in File B has its own line, and is a string), appears in File B.
I would use count if
in Excel
to get this going, but I don´t know how to do something simular in Bash.
I tried to use
grep -wc File_B File_A
But this did not work for me, I guess its because this try´s to find the complete File_B in File_A, but that does not work.
Any help would be apprechiated.
Kind regards
Elias
grep
is not the right tool; tryawk
. If you want a total count trygrep -f File_B -wc Fila_A
. If what you search for is literal strings (not regular expressions) add the-F
option:grep -f File_B -Fwc Fila_A
.