2012-08-14 24 views
1

我與具有以下結構的一些NASTRAN輸入文件的工作列:的emacs - 添加十進制值數

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 

我發現了幾個例子來說明如何做到這一點的integers,但似乎無法得到這個,因爲我已經在例如工作如上所述。

在此先感謝您的幫助!

回答

2

在鏈接的問題它是可以做到的使用代替回答這樣的,例如:

CM-%

^\([^,]*,[^,]*,[^,]*,[^,]*,\)\([^,]*\)\(.*\)

回報

\,(concat \1 (number-to-string (+ 1.653 (string-to-number \2))) \3)

請注意,在您的示例中,第二行有比第一行多的列(逗號)。可能是一個錯字。

+0

是的,額外的評論應該是一個週期。感謝您的迴應。如何構建這些表達式有沒有很好的資源?我認爲這是我的主要問題... – 2012-08-14 19:16:44

+0

可能有這樣的資源,但我現在還不能告訴你。您可能想問問emacs幫助列表中有關這方面的人:http://news.gmane.org/gmane.emacs.help – Tom 2012-08-14 19:57:36

0

所屬的命令

(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)))))))