ed -s a2.txt
Edit (by line) file a2.txt, -s suppresses character counts that the editor displays.
Commands are read from stdin (output of echo command)
echo "0r a1.txt\nw\nq"
Gives commands to ed
0r a1.txt Insert file a1.txt before first line of file.
w Write file (a2.txt)
q Quit editor