Pass the output of grep to xargs
xargs
grep -rl "pattern" * | xargs p4 edit
The normal way to do this is to do:
grep -rl "pattern" * | p4 -x - edit
p4 help usage explains -x:
p4 help usage
-x
The -x flag instructs p4 to read the arguments, one per line, from the specified file. If you specify '-', standard input is read.
I think this information is might useful to someone. First run following command to open all files.
p4 edit ...
Make your changes and run following command to revert the files which are not modified.
p4 revert -a