Announcement

Collapse
No announcement yet.

Copying file content to many files

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Copying file content to many files

    Hi,

    I would like to ask you, how should I copy content of one certain file to many others files, using bash.
    For example, I have the file /home/user1/index.html and I want to copy its content to all .html files in the same directory.
    Is there any good method for that?

    Thanks in advance

    #2
    I would make a backup of all the files, then change the extension of the source file so it differs from the others (or move it to a different directory), then do the content copy. This should do it in one command:

    zip allhtml.zip *.html; mv index.html index; for FILE in *.html; do cat index >> $FILE; done; mv index index.html


    This renames index.html to index, appends the contents of it onto the end of every file ending in .html, then renames index back to index.html. You might want to test this on a couple files separately first BEFORE running it on the whole batch so you're sure the results are what you want, or wait for someone smarter with a better idea

    If it messes up, unzip the allhtml.zip file and you'll have all the originals.


    Please Read Me

    Comment

    Working...
    X