Have you tried compute group/group? See http://lammps.sandia.gov/doc/compute_group_group.html
Thanks for your suggestion Stan. I tried the compute group/group command but it cannot output atom attributes like fx, fy and fz. Also, it includes an energy interaction term in the results.
Jingchao