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.
A
|-- 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.
A
|-- 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.
Комментарии
Отправить комментарий