I want to copy a rubric.docx file to multiple files with names such as F20161368.docx, F20161981.docx, F20161983.docx... from a list of names in a MS Excel or text file.
Please help with a command or script to do that.
Linux Command to Copy Multiple Files?
Re: Linux Command to Copy Multiple Files?
Here's your starter:
Code: Select all
for i in F20161368.docx F20161981.docx F20161983.docx
do
cp rubric.docx $i
done
Re: Linux Command to Copy Multiple Files?
Thanks, but the F20161368.docx F20161981.docx F20161983.docx files do not exist and need to be created as a copy of rubric.docxMartinR wrote: ↑2020/02/07 12:18:05Here's your starter:
Code: Select all
for i in F20161368.docx F20161981.docx F20161983.docx do cp rubric.docx $i done
Re: Linux Command to Copy Multiple Files?
That's exactly what the script does. You may find this link https://www.gnu.org/software/bash/manual/bash.pdf useful.
* Line 1: Variable i will take the values F20161368.docx, F20161981.docx and F20161983.docx in turn for three passes around the loop.
* Line 2: The start of the loop
* Line 3: The value held in i is substituted for $i, giving for instance cp rubric.docx F20161368.docx, the the line is executed.
* Line 4: The end of the loop.
* Line 1: Variable i will take the values F20161368.docx, F20161981.docx and F20161983.docx in turn for three passes around the loop.
* Line 2: The start of the loop
* Line 3: The value held in i is substituted for $i, giving for instance cp rubric.docx F20161368.docx, the the line is executed.
* Line 4: The end of the loop.
Re: Linux Command to Copy Multiple Files?
Code: Select all
for file in $(cat <text file with list of file names in it>); do cp rubric.docx $file; done
Re: Linux Command to Copy Multiple Files?
That will work with a text file but I doubt it would with Excel - that's why I gave the literal approach.
To emacsx: Whoever's script ib built up as follows:
* $(cat <text file with list of file names in it>) - this runs first and lists the file into a single line.
* for file in <list of names> ; - Just as my annotated example, but the variable is called "file", not "i". The semicolon marks the logical end of line.
* do cp rubric.docx $file; done - My lines 2, 3 and 4 written as a single line.
How many file names are there to copy to? There is a limit to the above expansion and there is a way around it, but it gets a little more complex .
To emacsx: Whoever's script ib built up as follows:
* $(cat <text file with list of file names in it>) - this runs first and lists the file into a single line.
* for file in <list of names> ; - Just as my annotated example, but the variable is called "file", not "i". The semicolon marks the logical end of line.
* do cp rubric.docx $file; done - My lines 2, 3 and 4 written as a single line.
How many file names are there to copy to? There is a limit to the above expansion and there is a way around it, but it gets a little more complex .