bash guru 😉 I’m trying to improve some string in bash which grep specific keyword’s matches in specific files. It looks like that:
find /<path>/hp -iname '*.ppd' -print0 | xargs -0 grep "\*ModelName\:"
which works very fast for me! In 20 times faster than this one:
find /<path>/hp -iname '*.ppd' -print0 | xargs -0 -I {} bash -c 'grep "\*ModelName\:" {}'
But the problem is that in the first script I’m getting the following lines:
/<path>/hp/hp-laserjet_m9040_mfp-ps.ppd:*ModelName: "HP LaserJet M9040 M9050 MFP"
but desired result is just
*ModelName: "HP LaserJet M9040 M9050 MFP"
(as in the second script). How can I achieve it?
P.S.: I’m using find for flexibility and future improvements of the script.
The
-hoption togrepsuppress filenames from the output.If your
grepdoes not provide-hthe usecat:Also, for your information,
findprovides the-execoption which would renderxargsunnecessary had you wanted to pursue your second option: