我有两个文件,file1.traj和file2.traj。这两个文件都包含相同的数据,数据以相同的格式排列。 这两个文件的第一行是注释。在两个文件的第7843行,有笛卡尔坐标X,Y和Z.在第15685行 还有另一个笛卡尔坐标X,Y和Z.两个笛卡尔坐标之间的行数是7841.
我想要做的是在整个文件中仅复制从file1.traj到file2.traj的X Y Z坐标。 我尝试使用粘贴命令,但我不能单独使用指定的行。
这里我展示了文件中的数据格式。为了清晰起见,我使用了这个数字。
line.1 trajectory generated by ptraj
line.2 5.844 4.178 7.821 6.423 4.054 8.578 6.606 4.907 6.827 7.557
line.3 4.385 6.722 6.877 6.384 7.283 5.950 6.884 7.565 7.668 6.282
line.2 8.474 7.721 7.127 8.928 7.628 7.205 6.259 8.589 6.712 6.110
line.3 7.712 8.602 6.643 8.151 8.654 7.495 6.940 7.183 4.871 6.108
line.4 7.887 4.864 7.755 7.814 3.754 8.697 7.267 3.724 7.081 7.633
line.5 2.478 6.246 8.089 2.604 8.026 8.853 3.943 6.623 5.754 4.529
.
.
.
. 1.516 41.749 54.260 0.108 41.176 54.536 -0.626 40.627 53.818 -0.303
. 41.920 42.179 3.556 3.251 41.623 3.530 2.472 42.558 2.678 3.304
. 44.723 1.496 5.937 44.339 1.355 6.803 44.866 0.614 5.593 52.401
line.7842 86.323 2.974 52.385 85.816 3.785 51.879 85.808 2.359
line.7843 104.140 159.533 88.303
line.7844 4.792 5.052 8.317 5.279 4.463 8.898 5.663 5.341 7.220 6.267
line.7845 4.438 7.137 6.477 6.566 7.627 5.857 7.407 7.936 7.301 6.170
. 8.741 7.647 7.020 9.023 7.315 7.107 6.475 8.171 6.435 6.413
. 7.823 8.416 6.704 8.208 8.473 7.582 6.560 7.126 5.141 5.816
.
.
.
. 52.050 7.905 42.026 38.561 1.747 39.847 39.375 2.235 39.972 38.634
. 1.382 38.965 0.810 0.477 39.394 0.717 -0.349 39.867 0.222 1.081
. 39.847 43.073 5.033 2.756 43.387 5.428 1.942 42.256 4.598 2.511
line.15683 47.302 4.261 7.071 47.801 4.632 7.799 47.256 4.968 6.428 54.279
line.15684 0.498 3.477 53.964 0.612 2.580 53.500 0.612 4.021
line.15685 104.140 159.533 88.303
line.15686 4.970 4.868 7.979 5.342 4.250 8.612 5.988 5.450 7.184 6.903
line 15687 4.861 7.246 6.381 6.921 7.550 5.526 7.597 7.536 6.953 7.009
.
.
是否有可能使用awk或sed?
答案 0 :(得分:0)
使用AWK你可以做到,我不认为它是完美的答案,但它很棘手
sushanth @ mymachine:〜$ cat file1.txt
104.140 159.533 88.303
5.844 4.178 7.821 6.423 4.054 8.578 6.606 4.907 6.827 7.557
4.385 6.722 6.877 6.384 7.283 5.950 6.884 7.565 7.668 6.282
8.474 7.721 7.127 8.928 7.628 7.205 6.259 8.589 6.712 6.110
104.140 159.533 88.303
7.712 8.602 6.643 8.151 8.654 7.495 6.940 7.183 4.871 6.108
7.887 4.864 7.755 7.814 3.754 8.697 7.267 3.724 7.081 7.633
2.478 6.246 8.089 2.604 8.026 8.853 3.943 6.623 5.754 4.529
这里我使用awk
仅使用了35个字符或更长的打印行sushanth @ mymachine:〜$ cat file1.txt | awk'length< 35'> FILE2.TXT
104.140 159.533 88.303
104.140 159.533 88.303