I am very new to shell scripting in linux.
I have a bunch of files in source directory. I have to move the files to the target directory where the folder should contains the file name(not exact match).
Ex: My source directory
/var/backup/
adbs.spec
dmsxlogstash-avi-core.spec
fomru32logstash-core.spec
gendftpcore.spec
My destination directory
/path
/adbs_32
/dmsx_ty_32logstash-avi-core-2.2.0
/fomru_ts_tdlogstash-45core-2.1.1
/gend_monitorftpcore.spec-2.0
I have written a script based on the reference but my script is not working. The files are not get copied to the target directory
for path in /var/backup/${1}
do
if [ -f "${path}" ]
then
filename="$(<<< "${file}" awk -F'.')"
if [ -n "${filename}" ]
then
cp "${path}" "/path/${1}/"
fi
fi
done
Thanks in advance
Update as per the clarification in the comments:
I have mentioned the target directory "/path/${1}/" in cp "${path}" "/path/${1}/".
I want to read the filename from the source directory and I have to search the foldername containing filename and need to move the file to the matched folder. This is my requirement.
Update2 I have modified filenames and directory names.