I want my script to copy the files in addresses.list (which contains the absolute path of those files) in my folder3 adding to the name of files the variable k (name of the lower folders they came from).
The script makes sense to me but it does not work, it states:"cp: cannot create regular file"; any suggestions?
#!/bin/bash
cd /folder1/
for k in $( cat lowerfolders_list ); do
for f in $( cat addresses.lst ); do
cp $f "/folder1/folder2/folder3/${k}_$f"
cd /folder1/
done
done
The exact error I get is this " cp: cannot create regular file `/A/B/C/D/E/folder1/folder2/folder3/name of my $k/path_to_my_file/myfile.sdf': No such file or directory "
EDIT
It would be ok even if I could copy those files naming them only after the $k but when I tried to do this my output is the last file in my addresses.lst multiple times with every name on my lowerfolders_list. This is the script I used:
#!/bin/bash
cd /folder1/
for k in $( cat lowerfolders_list ); do
for f in $( cat addresses.lst ); do
cp "$f" "/folder1/folder2/folder3/${k}"
done
cd -
done
Any suggestions?
EDIT Resolved
#!/bin/bash
cd /folder1/
for k in $( cat lowerfolders_list ); do
for f in $( cat addresses.lst ); do
myfile=$( basename "$f" )
cp "$f" "/folder1/folder2/folder3/${k}_${myfile}"
done
cd -
done
Thanks to all the people that contributed.