I have a directory hierarchy named, for example, abc
and a text file names.txt
. I need to choose several lines from the text file and then create new files with sample text, say "Hello world", in every sub-directory of the abc
, where every chosen line from the names.txt
is the name for one of the new files. I have to do it in one line using xargs
or -exec
. I've tried something like this but it doesn't seem to work:
find abc -type d -exec sh -c 'grep ^'A' names.txt | xargs -I% sh -c 'echo 'Hello world' | tee {}/%'' \;
How to do this the right way?