NewUsr_stat
NewUsr_stat

Reputation: 2583

Copy files from subfolders to the nearest parent directory in Unix

I have the following folder structure:

Folder1       
--FolderA    
  --Gex_experiments     
--FolderB     
 --Gex_experiments     
--FolderC    
 --Gex_experiments    
.......      
--FolderAYCD
 --Gex_experiments

In each Gex_experiments folder there's a *_GEX.txt file I would like to move to FolderA in the case of Gex_experiments folder under FolderA, to FolderB in the case of Gex_experiments folder under FolderB and so on.

Can anyone help me please?

Best!

Upvotes: 0

Views: 86

Answers (1)

user3616528
user3616528

Reputation: 68

From folder1 you can run:

for file in *; do
  if [ -d $file ]; then
    cd $file; mv Gex_experiments/*_GEX.txt ./; cd ..;
  fi
done

Upvotes: 1

Related Questions