I have a file with the following text (file1)-
1SER CA 1 1.401 0.040 0.887
2GLN CA 2 1.708 -0.155 1.002
3ALA CA 3 1.870 -0.103 0.662
4GLU CA 4 1.829 0.274 0.695
I have a separate file with similar text (file2)-
1MET CA 1 17.704 15.987 17.370
2ARG CA 2 17.811 16.145 17.712
3ARG CA 3 17.634 16.267 18.034
4TYR CA 4 17.465 16.615 18.002
My aim is to replace the characters in range 2-4 in file1 with the data in 2-4 of file2.
Desired output-
1MET CA 1 1.401 0.040 0.887
2ARG CA 2 1.708 -0.155 1.002
3ARG CA 3 1.870 -0.103 0.662
4TYR CA 4 1.829 0.274 0.695
i.e. the characters from 2-4 of file2 are placed in the bytes 2-4 of file1.
I know I can narrow down on the required region with cut -c 2-4 | sed ...
but I'm not able to 'read' the data from a separate file and replace in place.
I have a feeling that it might be easier in awk but no column based answers please. It needs to be a solution based on the range of characters in the file (in this case 2-4).
ADDED EXAMPLE
The solution should be able to do this as well- file1-
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
file2-
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
Output-
ABBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
ABBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
ABBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA