I'm trying to figure out how to move a block of text from one file to a specific point in another. I have a large amount of files that looks like this:H                 -9.92247800    1.33807800   -0.69208300  S                 -9.74392800    0.01073000   -0.55448800   C                 -7.98603700    0.04294200   -0.19355700   C                 -7.45325900   -1.23715800    0.02112600...  And I want to move the columns of numbers to files that looks like this before:...0 1 0 1 0 1H                0  HS                0  HC                0  HC                0  H...And so should like this after:  ...0 1 0 1 0 1H                0 -9.92247800    1.33807800   -0.69208300 HS                0 -9.74392800    0.01073000   -0.55448800 HC                0 -7.98603700    0.04294200   -0.19355700 HC                0 -7.45325900   -1.23715800    0.02112600 H...Is there anyway to automate this for a large number of files? I'm aware that I can select a block, copy it, and paste it into the other file manually, but I have too many files for this to be feasible.If it helps, the number blocks always begins and ends at the same location (line and column) and the place I want to paste to always is at the same line and column.
Copy a block of text to a specific point in another file
text processing;files;scripting;columns
Don't know if you are up for Python, and there is likely a pithy way using a different language, but Python can do this with something like:Code:# describe where the text block is locatedf1_start = 2, 18f1_size = 4, 40f2_start = 4, 19# open all three fileswith open('file1', 'rU') as f1, open('file2', 'rU') as f2, open('file3', 'w') as f3:    # skip some lines in file1    for _ in range(f1_start[0] - 1):        f1.readline()    # write first block of file2 to file3    for _ in range(f2_start[0] - 1):        f3.write(f2.readline())    # read from and merge lines in file1 and file 2    for _ in range(f1_size[0]):        l1 = f1.readline()[f1_start[1]:f1_start[1] + f1_size[1]].rstrip()        l2 = f2.readline()        l3 = l2[:f2_start[1]] + l1 + l2[f2_start[1]:]        f3.write(l3)    # write remaining lines from file2 to file3    while True:        l2 = f2.read()        if not l2:            break        f3.write(l2)Result:...0 1 0 1 0 1H                0 -9.92247800    1.33807800   -0.69208300 HS                0 -9.74392800    0.01073000   -0.55448800 HC                0 -7.98603700    0.04294200   -0.19355700 HC                0 -7.45325900   -1.23715800    0.02112600 H...