Question

Let's say I have text file called template.txt. template.txt contains the text "hello world."

I also have 10 other files named, message1, message2, message3, ect.

How can I copy the contents of template_message into message1, message2, message3, ect?

So far I've tried:

cp --copy-contentes template.txt *

cp --copy-contentes template.txt | xargs ls
Was it helpful?

Solution

With a loop:

for file in message*
do
    cp template.txt "$file"
done

OTHER TIPS

yet another way of doing this

ls message* | xargs -n1  cp template.txt

Use a for loop and append the index to the end of your destination file.

for i in {1..10};
do
    cp template.txt "message$i"
done
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top