Find directories by file extension and copying/moving somewherelse

I want to search by file extension and by texts and then copy a binary file inside the same folder. For instance, I am in directory A and finally like to copy all *.gdx files (in B,C,D) to somewhere.

|-- B                             
|   |-- file1.out (a text file)                   
|   |-- file1.gdx (a binary file)           

|-- C       
|   |-- file2.out (a text file) 
|   |-- file2.gdx (a binary file) 

|-- D       
|   |-- file3.out (a text file) 
|   |-- file3.gdx (a binary file) 
Here is my code:
cd 'find . -maxdepth 2 -name "*.out"|xargs grep "sometext"| awk -F'/' '{print $2}'|sort -u ' && ' find . -maxdepth 2 -name "*.gdx" -print0|xargs -0 cp -t /somewhere'
The problem here, if first find captures multiple folders then copy only one *.gdx file from the first folder, not all *.gdx files from all folders. I believe it has to be done by loop, but don't know how to script.

Комментарии

Популярные сообщения из этого блога

FillChar and StringOfChar under Delphi 10.2 for Win64 Release Target

Intuition behind successive squaring.