Question

I have a list full of filenames (in each line is one filename). How can I copy a file (for e.g. text.txt) multiple times and rename it (example1.txt, example2.txt so on). At the end I want multiple files with the content of text.txt but with the filenames of my list. Is this possible?

Was it helpful?

Solution 2

while read line; do
    cp text.txt "$line"
done < text.txt 

You loop over all the lines in the file, and for each filename you invoke a separate cp command.

OTHER TIPS

Assuming no spaces in the filenames in your list:

for f in $list; do cp text.txt $f; done

If there are spaces, and assuming bash:

while IFS= read -r f; do cp text.txt "$f"; done <<< "$list"

This might work for you (GNU sed):

sed 's|.*|cp -v text.txt "&"|e' list.txt
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top