You may find it hard to grep a multi-line pattern. As this answer expalined, you probably need to use pcregrep
:
pcregrep -M -f "$license_file" "$c_file"
This however has some problems in it because it neither check the position (file start in your case) nor the pattern is for multi-line form. First, the content in $license_file
should be like
line 1\nline2\nline 3\nline 4\n
So if you can edit the content of $license_file
to the required format then the problem can be proceeded as
pcregrep -HMf"$license_file" --line-offsets "$c_file" | grep -o "^$c_file:1:" | sed 's/...$//'
The --line-offsets
option will report the matching line number, so we grep line number 1 and strip the line number to report the matching filename. (Because we know the line number=1 and content is that in $license_file
so I suppose you want to report the matching filenames.)
If you may not edit $license_file
you could replace it by sed
:
pcregrep -HMf <(sed -En '1h;2,4H;4{x;s/\n|$/\\n/g;p}' "$license_file") --line-offsets "$c_file" | grep -o "^$c_file:1:" | sed 's/...$//'