0

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?

Kimble
  • 3
  • 2
  • 1
    this has nothing to do with sed or grep – glenn jackman Nov 19 '13 at 17:31
  • welcome to stack overflow. It As @glennjackman pointed out, your question doesn't really directly relate to sed or grep (though I suppose you could write a script using those commands). I would look into the rename command see http://stackoverflow.com/a/1086509/505191 – thekbb Nov 19 '13 at 17:44

3 Answers3

2

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"
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
1
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.

pfnuesel
  • 14,093
  • 14
  • 58
  • 71
0

This might work for you (GNU sed):

sed 's|.*|cp -v text.txt "&"|e' list.txt
potong
  • 55,640
  • 6
  • 51
  • 83