Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appending the contents of a file at the beginning of another file in UNIX [closed]

Tags:

linux

shell

unix

I know that

cat file1 >> file2 

would append the contents of file1 at the end of file2. On the other hand, how can I append the contents of file1 at the beginning of file 2, and not at its end?

Actually, i have a single master file M, and several other files in a directory D. I want to append the contents of file M at the beginning of all the files in the directory D.

like image 491
London guy Avatar asked Jan 08 '13 09:01

London guy


Video Answer


2 Answers

Just do:

cat file1 file2 > tmp && mv tmp file2
like image 117
Chris Seymour Avatar answered Sep 28 '22 10:09

Chris Seymour


For each file you could do:

cat MASTER file >> file.tmp

And then move file.tmp over file.

like image 28
cnicutar Avatar answered Sep 28 '22 08:09

cnicutar