I'm trying to write a script that will copy all file listed in a text file, around 3 million lines, which contains two columns, the source and the destination with a new filename:
path/to/source/directory/filename.pdf path/to/destination/directory/Newfilename.pdf
path/to/source/directory/filename2.pdf path/to/destination/directory/Newfilename2.pdf
path/to/source/directory/filename3.pdf path/to/destination/directory/Newfilename3.pdf
...
All files are PDF format, where Newfilename.pdf is the new filename for the same source PDF file.
ADDITIONALLY, I would like to copy the file and add information to its destination filename, i.e.:
From:
Newfilename.pdf
To:
Newfilename_yyyyMMddHHmmss.pdf (e.g. Newfilename_20200225095823.pdf)
Where yyyyMMddHHmmss is the actual copy executing date and time for each file and this is the same format for all, causing the destination file to be copied with its complemented name:
path/to/destination/directory/Newfilename_20200225095823.pdf
path/to/destination/directory/Newfilename2_20200225095824.pdf
path/to/destination/directory/Newfilename3_20200225095830.pdf
...
I do not have enough knowledge to handle commands, an idea of what I was researching is the following:
#!/bin/bash
filename=$1
while read -r source destination; do
# reading each value
cp -p source destination
done < $filename
However, I read some similar publications, for performance, the while loop and read are tremendously slow when reading from a file or a pipe, because the read shell built-in reads one character at a time. Reference here.
How it could be done with a better solution?
I will greatly appreciate your help.