I need to figure out how many times a location (columns 1 and 2) is present within a group of files. I figured using a combination of 'while read' and 'grep' I could count the number of instances but its not working for me.
cat file.txt | while read line
do
grep $line *08-new.txt | wc -l
done
The contents of column 3 are arbitrary in this case. Note that all locations in file.txt (source input) should have at least 1 instance in *08-new.txt, but there could be locations in *08-new.txt that are not in file.txt (source input). The files are titled {1981..2016}08-new.txt
file.txt (source input)
30.68 -88.24 34
32.30 -86.41 0.26
35.14 -111.67 1.27
33.43 -112.00 -0.08
34.65 -112.43 0.63
32.13 -110.96 0.60
198108-new.txt
30.68 -88.24 1.14
32.30 -86.41 0.26
35.14 -111.67 1.27
33.43 -112.00 -0.08
34.65 -112.43 0.63
32.13 -110.96 0.60
198208-new.txt
30.68 -88.24 1.14
32.30 -86.41 0.26
35.14 -111.67 1.27
30.48 -87.19 0.51
34.65 -112.43 0.63
32.13 -110.96 0.60
201608-new.txt
30.68 -88.24 1.14
32.30 -86.41 0.26
35.14 -111.67 1.27
33.43 -112.00 -0.08
34.65 -112.43 0.63
39.94 -91.19 1.80
Output
grep: invalid option -- .
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
0
Expected output
30.68 -88.24 3
32.30 -86.41 3
35.14 -111.67 3
33.43 -112.00 2
34.65 -112.43 3
32.13 -110.96 2
In the end I need to be able to have each location and its count (column 3) stored in a variable to be used further down the script.