Article 4Z861 Copying files with different extensions but one of them contains 'pattern'

Copying files with different extensions but one of them contains 'pattern'

by
sandykoufax
from LinuxQuestions.org on (#4Z861)
I have several files in a directory and need to copy to a different location those which contain within the file -not within the name- a certain string.
After that, I also need to copy another set of files with matching names but different extensions to the same location as those which matched my previous search.

So far I know how to find the string using

grep 'pattern' *.ext1

and I tried to use

grep 'pattern' *.ext1 | xargs cp /newlocation

but to no avail.
Thank youlatest?d=yIl2AUoC8zA latest?i=-R0BVNwDzEA:MTeGaaXul6k:F7zBnMy latest?i=-R0BVNwDzEA:MTeGaaXul6k:V_sGLiP latest?d=qj6IDK7rITs latest?i=-R0BVNwDzEA:MTeGaaXul6k:gIN9vFw-R0BVNwDzEA
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments