Score:0

How to copy files into a new file

cn flag

How to copy files from one file to another file that has contents I want to keep? In other words, I want the contents of file1 to go in file2 but the info in file1 to be added to the existing stuff in file2 ? The format in file2 should ideally have file2 info first then file1. Then I want to add file3 to file2 with the contents in file2 resulting in an output format of 1. File2 contents then 2. File1 contents and lastly file3 contents. All the files are in different directories. I would think a simple cp file1 file2 or cat file1 >> file2 would work but for some odd reason when I view file2 afterwards it only shows file1 info. Thank you in advance.

Score:2
mw flag

I think what you are lookig for is to append which is done using >> symbol:

Let say you have file1 with the content I'm file1 and file2 with the content I'm file2

Then you can do:

cat file1  >> file2   

This appends content of file1 to the end of file2.

now the result of file2` will be:

I'm file2
I'm file1

You can repeat the same command to add more as many more files as you like to the bottom of a file.

Score:1
jp flag

Let us say that you have file1, file2, file3 ... Then I suggest that you

  • either create a target file. Then the command

    cat file* > target
    
  • or have a target file and want to append to it. Then the command

    cat file* >> target
    

will do what you want.

Elon_s_mom avatar
cn flag
Thank you both! I will try that !
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.