Prepend data from one file to another
How do I prepend the data from file1.txt to file2.txt? The following command will take the two files and merge them into one cat file1.txt file2.txt > file3.txt; mv file3.txt file2.txt You can do this in a pipeline using sponge from moreutils : cat file1.txt file2.txt | sponge file2.txt Another way using GNU sed: sed -i -e '1rfile1.txt' -e '1{h;d}' -e '2{x;G}' file2.txt That is: On line 1, append the content of the file file1.txt On line 1, copy pattern space to hold space, and delete pattern space On line 2, exchange the content of the hold and pattern spaces, and append the hold space to