I have 4 directory
Dir1
file1 file2 file3 file4
Dir2
file3 file5 file6 file8
Dir3
file1 file2 file6 file9 file10
Dir4
file3 file6 file12 file15
and all the 4 dirs are having couple of files.
Few of the files are common to other directory/ies and few of them are brand new.
I need a finaloutput as
dir1 having all the files from all other 3 directory but not having its original files same for other dirs. And i need to change the file name in dir1. Actually all the files are having a ext as .text so i need to remove the .text from all the files.
eg
dir1 file5 file6 file8 file9 file10 file12 file15
dir2 file1 file2 file4 file9 file10 file12 file15
I am doing like this
newdir1 - copying all the files from dir2 dir3 and dir4
then delete the files from newdir1 which are there in dir1
so this way newdir1 is my final result.
Doing the same for other directory
>mkdir newdir1
> cp dir2/* ./newdir1
> cp dir3/* ./newdir1
> cp dir4/* ./newdir1
ls dir1 | while read file; do
rm ./newdir1/${file}
done
cd newdir1
ls | while read file; do
mv ${file} `echo ${file} | sed 's/\.txt//'`
done
Is there any other best and fast way to do? Actually i need some way which can be much more efficient than this instead of using 2 while loops as i have more than 5000 files in each folder and most of them are common across each folder only 20 are new files.
can i do this through file manipulation means instead of working on actual file if i make a file with all the filename and then doing some commands on names instead of actual file and then finally copying the actual file