shell - How do I batch copy and rename files with same name in different path? -
i have set of folders, inside each folder have several sub-folders. in each sub folder there file called result.txt need result.txt copied other location renaming result files.
folders:
abc1 efg1 doc2 ghih
sub-folders: in aaa1
1.abc1.merged 2.abc1.merged 3.abc1.merged 4.abc1.merged
in efg1
1.efg1.merged 2.efg1.merged 3.efg1.merged 4.efg1.merged 5.efg1.merged ... ...
so on of sub-folders contain result.txt in single different folder result files renamed result1.txt,result2.txt etc.
i tried set name of sub-folder variable in shell script , made loop go in sub-folder , copy result.txt other path , rename mv command.but result.txt file 1 subdirectory each copied not all.
i tried following commands:
cp $folder/$subfolder/resu*txt ../tsv/$newfolder/
(i assigned variables)
mv ../tsv/$newfolder/resu*txt ../tsv/$newfolder/results$tts.txt
(i defined $tts number of subfolders in folder)
this copied result.txt first sub-folder in each of parent folders.
i like:
i=1 dir in **/*; # loop through files cp "$dir"/result.txt $your_path/result$i.txt ((i++)) # increment variable $i done
the syntax **/*
goes through subdirectories.
test
$ mkdir $ cd $ mkdir a{1..4} $ mkdir a{1..4}/a{1..4} $ f in **/*; echo "$f --"; done
the last command returns
a1/a1 -- a1/a2 -- ... a4/a4 --
Comments
Post a Comment