paste the contents of one file into another file using Vi [closed]

How can I copy content from one file, and in another file somehow delete the original content and then paste the contents of the first file using vi editor? Or can it be done using another editor easily?


One solution would be to:

cat originalfile.txt >> newfile.txt

and then remove the original file. It would simplify for us if you let us know exactly what you are trying to achieve.


Open both files:

vi fileToChange fileToCopyFrom

Start in the file you want to delete content from permanently to replace with new content. (move between files with :n and :N) To delete all the contents, press esc if needed and type

dG

now save the change and move to the other file

:wn

(replace n with N if you started in the second file - you will see what I mean when you try)

In the other file, type

dG

this cuts the text so you can paste it. Now move back to the other file, without saving the change in this file (so the content will not be deleted)

:N!

and paste the new content:

p

If you want to undo something you can press u


there is many way to do this:

if you just want to replace one file content with other file content then you can do like :

  1. copy command :

    cp file anotherfile
    
  2. cat command:

    cat file > anotherfile
    
  3. If you want to use editor then you can use gedit editor :

    gedit file
    

select complete file content Ctrl+ a and open another file with gedit and replace content

gedit anothefile

there is many editor and method to replace content. you have to decide which one is comfortable for you.