unix脚本问题,该如何计算stdinput,stdoutput,以及stderror到一个findwaldo的文件

unix如何emacs编写脚本,找到stdinput,stdoutput,stderror各自出现的次数内容如下.

img

img

img

puzzle1可以输入0-99页,然后其中某一页会存在waldo,以及比如说puzzle1.sol文件就告诉了我们puzzle1的解是在42页,一个stdinput,其他都是0.

https://github.com/appavooteaching/ps1b-Zeyu-hub/blob/main/README.md
课上的文件,以及指导,但是看了6-7小时没看懂.

关于emacs --script的脚本操作,可以参考
下面的例子示范了shell script中最常用的几个任务:

  1. 读取命令行参数
  2. 遍历命令行参数
  3. 输出到stdout
  4. 输出到stderr
  5. 执行外部命令
  6. 获取外部命令输出
#hello.el
#!/usr/local/bin/emacs --script

;; find your emacs with : "which emacs" and set to the first line

(princ "This is message to stdout\n")

(message "This is err message to stderr")

(setq args command-line-args)

(princ (format "\nread command line with variable : %s\n" args))

(princ "\nenum arguments with car\n")

(setq i 0)

(while (setq arg (car args))

(princ (format "arg[%d] = %s\n" i arg))

(setq args (cdr args))

(setq i (1+ i)))

(princ "\nenum arguments with nth\n")

(setq args command-line-args)

(setq i 0)

(while (setq arg (nth i args))

(princ (format "arg[%d] = %s\n" i arg))

(setq i (1+ i)))

(princ "\nrun shell command with shell-command-to-string\n")

(setq ret (shell-command-to-string "date"))

(princ (format "shell execute result = %s" ret))

(princ "\nstart speed test\n")

(setq num 0)

(setq total 0)

(setq start (current-time))

(while (<= num 10000000)

(setq total (+ total num))

(setq num (+ num 1))

)

(setq end (current-time))

(princ (shell-command-to-string "date"))

(setq cost (- (nth 1 end) (nth 1 start)))

(princ (format "loop for %d times cost %d s\n" num cost))

(princ (format "speed = %d loops/s\n" (/ num cost)))

假设一页显示80行文本。你应该查找waldo出现那行的行数(可以用grep -n命令获得),然后用awk提取行数除以80就是页数。

./puzzle1 1 | grep -n waldo | awk -F: ‘{print $1/80}’