使所有首选列元素为零

Making all the preferred column elements to zero

 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  

如果模式是可预测的,find/replace 会起作用

%s/\v(\d+ \w+\s+([0-9\.]+\s+){3}).*/ 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
/                             - replace, insert the captured group
0 0 0 0 0 0 0 0 0               -          add required zero's

Regexbuddy 评论

// (\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, as many times as possible, 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, as many times as possible, 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, as many times as possible, 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, tab, line feed, carriage return, vertical tab, form feed) «\s+»
//          Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
// Match any single character «.*»
//    Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»