我正在使用一些具有以下结构的 nastran 输入文件:
GRID,1,,0.000,0.000,0.000,0
GRID,2,,0,000,1.653,0.000,0
我想做的是向单个列添加特定值,例如,将 1.653 添加到第 4 列并获得:
GRID,1,,0.000,1.653,0.000,0
GRID,2,,0,000,3.306,0.000,0
我找到了一些示例来展示如何对整数执行此操作,但似乎无法使其适用于我上面概述的示例。
在此先感谢您的帮助!
使用链接问题中的答案可以通过这样的替换来完成,例如:
C-M-%
^\([^,]*,[^,]*,[^,]*,[^,]*,\)\([^,]*\)\(.*\)
return
\,(concat \1 (number-to-string (+ 1.653 (string-to-number \2))) \3)
请注意,在您的示例中,第二行的列(逗号)比第一行多。可能是笔误。
分别作为命令
(defun raise-column ()
(interactive "*")
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(while (re-search-forward "^\\([^,]*,[^,]*,[^,]*,[^,]*,\\)\\([^,]*\\)\\(.*\\)" nil t 1)
(replace-match (concat (match-string-no-properties 1) (number-to-string (+ 1.653 (string-to-number (match-string-no-properties 2)))) (match-string-no-properties 3)))))))