Please, help me write this simple script using bash scripting.
Task:
In Folder1 I have files:
name1.txt, name2.txt, name3.txt .. etc
In Folder2 may located such files:
name1.txt, name2.txt .. etc
In Folder3 may located files like:
name1.txt_abc{some_symbols}_vxz, name2.txt_abc{some_symbols}_vxz ... etc - it's the same files as in Folder1 and Folder2, only the names are different.
So, I must to copy files from Folder1 To Folder2, if the file doesn't exist in Folder2 OR Folder3.
Example:
I must to copy file name4.txt to Folder2 if Folder2 doesn't contain name4.txt OR Folder3 doesn't contain file with name like name4.txt_{something}
cd to $path/folder1
ls -l name*.txt > files_list
for i in `cat files_list`
do
file_name=$i
new_file_name='$file_name'_abc{symbol}_vxz
cp $file_name $path/Folder2/$new_file_name
done
will return non-zero even if $file exists in one of the dirs (but doesn't in the other). You are also missing keyword 'in' in the for loop.
@ rajesh_pola: The quotes around '$file_name' will prevent this variable from expanding. Besides that, you never look into Folder3, instead you hardcoded _abc{symbol}_vxz ...
How about this?
cd Folder1
for f in * ; do
[[ -f /path/to/Folder2/$f ]] && echo "$f found in Folder2" && continue
ls /path/to/Folder3/${f}* &> /dev/null && echo "$f found in Folder3" && continue
cp $f /path/to/Folder2
done