[英]Bash scripting to remove specific portion
I want to write a script that will convert a fractional coordinate system into a Cartesian coordinate system. 我想编写一个脚本,将分数坐标系转换为笛卡尔坐标系。
Here, In the input file i have some unnecessary section i want to remove them. 在这里,在输入文件中,我有一些不必要的部分要删除。 To remove upper unnecessary section i am just using
sed -i '1,7 s/.*//g' geometry.xyz
(first 7 lines are always not needed). 要删除上部不必要的部分,我只是使用
sed -i '1,7 s/.*//g' geometry.xyz
(始终不需要前7行)。 But my problem is the section i require may change in size. 但是我的问题是我需要的部分可能会更改大小。 This looks something like:
看起来像这样:
%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
Now i may have more Hydrogen or Oxygen or Carbon in my system. 现在我的系统中可能有更多的氢,氧或碳。 So, I want the script to find % and delete everything after that.
因此,我希望脚本查找%并在此之后删除所有内容。 Is it possible?
可能吗? Thanks
谢谢
awk '/%ENDBLOCK POSITIONS_FRAC/{ exit }; p; /%BLOCK POSITIONS_FRAC/{p = 1};' geometry.xyz
Would give 会给
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.