First Match - awk
How about
$ awk -F, 'NR==FNR {a[$1]; next} $1 in a {print; delete a[$1]}' file1 file2
foo,1
boo,1
A variation of the famous seen idiom.
awk -F, 'FNR==NR{a[$1]=1;next} a[$1]++==1' file1 file2
update
As @dave_thompson_085 pointed out, there might be multiple soo,#
in the second file, it cause a[$1]++==1
to be true for the second one. He also gives several ways to fix it:
awk -F, 'FNR==NR{a[$1]=1;next} !--a[$1]' file1 file2
Not actually awk
, but it works. And I suppose it allows for easy extension.
#!/usr/bin/env bash
while IFS= read -r line; do
grep -m1 "$line" "$2"
done < "$1"
$ ./script.sh file1 file2
Took the reading line-by-line from https://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable.
Then it's just 'find first match with content of line in file2'