开发者

copy and replacing from file1 to file specific line

I have two files, file1.traj and file2.traj. Both these files contain identical data and the data are arranged in same format in them. The first line of both files is a comment. At line 7843 of both files there is cartesian coordinat开发者_开发技巧e X, Y and Z. And at line 15685 there is another cartesian coordinate X, Y and Z. The number of lines in between two cartesian coordinates are 7841.

What I want to do is copy ONLY the X Y Z coordinates from file1.traj to file2.traj throughout the whole file. I tried to use paste command but I cant do for specified line alone.

Here i showed the data format in the file. I used the number for clarity purpose.

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
    .
    .

Is there any possibility to use awk or sed?


Using AWK you can do it,i don't think its perfect answer ,but its tricky

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

here i have used print only lines of 35 characters or longer using awk

sushanth@mymachine:~$ cat file1.txt | awk 'length < 35' > file2.txt

104.140 159.533  88.303
104.140 159.533  88.303
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜