我想编写一个脚本,将小数坐标系转换为笛卡尔坐标系。
这里,在输入文件中,我有一些不必要的部分,我想删除它们。要删除上部不必要的部分,我只使用sed -i '1,7 s/.*//g' geometry.xyz
(始终不需要前7行)。
但我的问题是我要求的部分可能会改变大小。这看起来像:
%BLOCK LATTICE_CART
10.000000000000000 0.000000000000000 0.000000000000000
0.000000000000000 10.000000000000000 0.000000000000000
0.000000000000000 0.000000000000000 10.000000000000000
%ENDBLOCK LATTICE_CART
%BLOCK POSITIONS_FRAC
H 0.3242730364399766 -0.5778932059463918 0.4725289033063597
H 0.3242730880505244 -0.4462573476378897 0.3408930320952251
H 0.5269396206127043 -0.6403171603506288 0.3779836353112689
H 0.4391824086567526 -0.6285598118052995 0.5417408894621464
H 0.6929877354648144 -0.5297761432888469 0.4524840992286400
H 0.6466039123419516 -0.6708589950924689 0.5647345854707825
H 0.6049230092979219 -0.4959539583844693 0.6129729324712603
H 0.4279396231283572 -0.3487419832103440 0.5700442724565965
C 0.3622730487068306 -0.4740752814020994 0.4447109742648412
C 0.4762730467994820 -0.4740752814020994 0.4447109742648412
C 0.5142730074557883 -0.5778932235717150 0.4725289080290508
C 0.6146969322498489 -0.5686205772550322 0.5256801349609578
O 0.5142730074557883 -0.3980752729966930 0.5207109826702476
%ENDBLOCK POSITIONS_FRAC
%BLOCK KPOINTS_LIST
0.0000000000000000 0.0000000000000000 0.0000000000000000 1.000000000000000
%ENDBLOCK KPOINTS_LIST
%BLOCK CELL_CONSTRAINTS
1 2 3
4 5 6
%ENDBLOCK CELL_CONSTRAINTS
FIX_COM : false
%BLOCK IONIC_CONSTRAINTS
%ENDBLOCK IONIC_CONSTRAINTS
现在我的系统中可能含有更多的氢或氧或碳。所以,我希望脚本找到%并删除之后的所有内容。可能吗? 感谢
答案 0 :(得分:0)
awk '/%ENDBLOCK POSITIONS_FRAC/{ exit }; p; /%BLOCK POSITIONS_FRAC/{p = 1};' geometry.xyz
会给予
H 0.3242730364399766 -0.5778932059463918 0.4725289033063597
H 0.3242730880505244 -0.4462573476378897 0.3408930320952251
H 0.5269396206127043 -0.6403171603506288 0.3779836353112689
H 0.4391824086567526 -0.6285598118052995 0.5417408894621464
H 0.6929877354648144 -0.5297761432888469 0.4524840992286400
H 0.6466039123419516 -0.6708589950924689 0.5647345854707825
H 0.6049230092979219 -0.4959539583844693 0.6129729324712603
H 0.4279396231283572 -0.3487419832103440 0.5700442724565965
C 0.3622730487068306 -0.4740752814020994 0.4447109742648412
C 0.4762730467994820 -0.4740752814020994 0.4447109742648412
C 0.5142730074557883 -0.5778932235717150 0.4725289080290508
C 0.6146969322498489 -0.5686205772550322 0.5256801349609578
O 0.5142730074557883 -0.3980752729966930 0.5207109826702476