简体   繁体   English

如何运行一个缓冲区的总和?

[英]How to run sum of a buffer?

So, from my log file, I processed some string and finally got this result in, let's say buffer name " 1 " 因此,从我的日志文件中,我处理了一些字符串,最后得到了这个结果,比方说缓冲区名称“ 1

12
23
34
45

How can I get a sum of a given buffer? 如何获得给定缓冲区的总和?

(defun sum-of-buffer (buf)
  (interactive "bBuffer Name: ")
   ....
  (message "%i" sum))

Or is there a convenient function combination? 还是有方便的功能组合?

How about using calc -- select the region in the shape of a rectangle -- and type: Cu Cx * : 如何使用calc选择矩形形状的区域-并输入: Cu Cx * :

Alternatively, how about?: 或者,如何?:

(let ((sum 0))
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward "[0-9]*\\.?[0-9]+" nil t)
      (setq sum (+ sum (string-to-number (match-string 0))))))
  sum)

If you're on a Unix machine, Cx h M-| 如果您在Unix机器上,请Cx h M-| and then awk '{s+=$1} END {print s}' . 然后awk '{s+=$1} END {print s}'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM