如何解决将所有首选列元素设为零
REFERENCE STRUCTURE = 00000 A,B,C = 120.000 120.000 42.560
ALPHA,BETA,GAMMA = 90.000 90.000 90.000 SPGR = P1
31984 1 new.pdb
x y z
1 C 8.17500 93.80900 21.90700 8 4 2 0 0 0 0 0 -0.036 1
2 C 9.34800 94.14800 22.73500 1 16 9 0 0 0 0 0 0.038 1
3 C 8.05800 95.47500 24.28800 6 9 15 0 0 0 0 0 0.038 1
4 C 6.95800 94.40500 22.32000 12 1 6 0 0 0 0 0 0.060 1
5 O 7.20600 96.40600 26.25200 15 0 0 0 0 0 0 0 -0.270 1
6 C 6.88800 95.13100 23.50200 4 10 3 0 0 0 0 0 -0.036 1
7 O 4.60000 94.52600 21.81800 1645872 0 0 0 0 0 0 0 -0.245 1
8 H 8.26600 93.17800 21.03500 1 0 0 0 0 0 0 0 0.063 1
9 C 9.25800 94.94800 23.85500 2 3 11 0 0 0 0 0 -0.037 1
10 H 5.98600 95.70100 23.66700 6 0 0 0 0 0 0 0 0.063 1
11 H 10.19600 95.24800 24.29800 9 0 0 0 0 0 0 0 0.063 1
12 C 5.70900 94.23600 21.42300 13454 7 4 0 0 0 0 0 0.337 1
13 O 5.87600 93.60100 20.21100 14 12 0 0 0 0 0 0 -0.477 1
14 H 5.04400 93.52600 19.73800 13 0 0 0 0 0 0 0 0.295 1
我具有此文件结构,需要将x,y和z列之后的所有列都设置为零,并删除最后一列。例如,我需要将以下内容作为输出(示例)。
1 C 8.17500 93.80900 21.90700 0 0 0 0 0 0 0 0 0
2 C 9.34800 94.14800 22.73500 0 0 0 0 0 0 0 0 0
解决方法
如果模式是可预测的,则可以查找/替换
%s/\v(\d+ \w+\s+([0-9\.]+\s+){3}).*/\10 0 0 0 0 0 0 0 0
故障
%s/ - substitute every line
\v - very magic
(\d+ \w+\s+([0-9\.]+\s+){3}) - capture everything between ()
searches for '1 C 8.17500 93.80900 21.90700 '
.* - remaining character after our captured group
/\1 - replace,insert the captured group
0 0 0 0 0 0 0 0 0 - add required zero's
预算外评论
// (\d+ \w+\s+([0-9\.]+\s+){3}).*
//
// Options: Case insensitive; Exact spacing; Dot matches line breaks; ^$ match at line breaks; Default line breaks; Numbered capture; Allow duplicate names; Greedy quantifiers; Allow zero-length matches
//
// Match the regex below and capture its match into backreference number 1 «(\d+ \w+\s+([0-9\.]+\s+){3})»
// Match a single character that is a “digit” (ASCII 0–9 only) «\d+»
// Between one and unlimited times,as many times as possible,giving back as needed (greedy) «+»
// Match the character “ ” literally « »
// Match a single character that is a “word character” (ASCII letter,digit,or underscore only) «\w+»
// Between one and unlimited times,giving back as needed (greedy) «+»
// Match a single character that is a “whitespace character” (ASCII space,tab,line feed,carriage return,vertical tab,form feed) «\s+»
// Between one and unlimited times,giving back as needed (greedy) «+»
// Match the regex below and capture its match into backreference number 2 «([0-9\.]+\s+){3}»
// Exactly 3 times «{3}»
// Match a single character present in the list below «[0-9\.]+»
// Between one and unlimited times,giving back as needed (greedy) «+»
// A character in the range between “0” and “9” «0-9»
// The literal character “.” «\.»
// Match a single character that is a “whitespace character” (ASCII space,form feed) «\s+»
// Between one and unlimited times,giving back as needed (greedy) «+»
// Match any single character «.*»
// Between zero and unlimited times,giving back as needed (greedy) «*»
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。