Article 58SFH How do I copy folders with a file in them that has a grep pattern and preserve the folder structure

How do I copy folders with a file in them that has a grep pattern and preserve the folder structure

by
voncloft
from LinuxQuestions.org on (#58SFH)
Basically I want to grep for the word "KDE" in /usr/ports/core and if a file in a subfolder matches I want to copy the folder with the files in it to another folder.

the command: grep -inrl "kde" /usr/ports/core | xargs cp -rv -p /Voncloft-OS/KDE

is almost working but not quite it moves the files to /Voncloft-OS/KDE

....but not the folder structure.

Thanks.latest?d=yIl2AUoC8zA latest?i=2EpjqUcAgpc:kyFVyH6YFwA:F7zBnMy latest?i=2EpjqUcAgpc:kyFVyH6YFwA:V_sGLiP latest?d=qj6IDK7rITs latest?i=2EpjqUcAgpc:kyFVyH6YFwA:gIN9vFw2EpjqUcAgpc
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