sed read contents of file and print value another file

Trying to use sed to insert the contents of a file into the end of each line in another file
file1

This is a line
Here is another line 
This is yet another line
Here is a fourth line

file2

TEXT

desired output

This is a line TEXT
Here is another line TEXT
This is yet another line TEXT
Here is a fourth line

This is what I'm trying with sed, thinking the dollar sign would put the text at the end of each line but it isn't. Any suggestions would be appreciated

sed '/$/ r file2' file1

That's not how it works. It prints the line incl. a <new line> char, and then reads and prints the text, regardless of the $ regex.
How about

sed '1 {x; d; n}; G; s/\n/ / ' file2 file1
This is a line TEXT
Here is another line  TEXT
This is yet another line TEXT
Here is a fourth line TEXT
1 Like

hm command garbled. I'm on Solarice, wonder if there is something about that.

Please show the error message in its entirety, char by char.

If file1 is only one line then one read command puts it into a shell variable.

read text < file1

Then a while read loop or sed can do add the text variable.

while IFS= read -r line
do
  printf "%s %s\n" "$line" "$text"
done < file2 > file3

Here the output is redirected to a new file.

hey RudiC

> cat file1
This is a line
Here is another line
This is yet another line
Here is a fourth line


> cat file2
TEST


> sed '1 {x; d; n}; G; s/\n/ /' file2 file1
sed: command garbled: 1 {x; d; n}; G; s/\n/ /

I'm not at home on solaris; does this help:

sed '1 {x; d; n; }; G; s/\
/ /;' file2 file1
1 Like