I want to prepend the data of a file (random.txt) into another set of files (real.txt) in a folder.
Take the following example:
$ cat random
some text
$ cat real.txt
sample text
If I run the following command:
$ sed i.old '1s;^;some text\n;' real.txt
$ cat real.txt
some text
sample text
This command prepends the text of file random into file real.txt, but the content of random is not fixed. Is it possible to redirect the content of the random into real.txt?
I tried the following command:
$ sed -i.old "1s;^;$(cat random)\n;" real.txt
$ cat real.txt
Which gives the output:
some text
sample text
The problem occurs when i my random fil gets a txt starting with "/*". It shows following error:
$ cat real.txt
/*new text
new line*/
$sed -i.old "1s;^;$(cat random)\n;" real.txt
sed: -e expression #1, char 16: unterminated `s' command