Many grep variants implement a recursive option.
E.g., GNU grep
-R, -r, --recursive
Read all files under each directory, recursively; this is equivalent to the -d recurse option.
You can then remove find:
grep -n -r $pattern $path | awk '{ print $1 }'
but this keeps more than the line number. awk is printing the first column. This example
src/main/package/A.java:3:import java.util.Map;
src/main/package/A.java:5:import javax.security.auth.Subject;
src/main/package/A.java:6:import javax.security.auth.callback.CallbackHandler;
will be printed as
src/main/package/A.java:3:import
src/main/package/A.java:5:import
src/main/package/A.java:6:import
notice the :import in each line. You might want to use sed to filter the output.
Since a : could be present in the file name you can use the -Z option of grep to output a nul character (\0) after the file name.
grep -rZn $pattern $path | sed -e "s/[[:cntrl:]]\([0-9][0-9]*\).*/:\1/"
with the same example as before will produce
src/main/package/A.java:3
src/main/package/A.java:5
src/main/package/A.java:6