我偶尔使用AWK来提取和/或反转数据文件中的列。
awk '{print $2,",",$1}' filename.txt
我该如何使用Emacs Lisp完成相同的操作?
(defun awk (filename col1 &optional col2 col3 col4 col5)
"Given a filename and at least once column, print out the column(s)
values in the order in which the columns are specified."
...
)
;; Test awk
(awk "filename.txt" 1); Only column 1
(awk "filename.txt" 2 1); Column 2 followed by column 1
(awk "filename.txt" 3 2 1); Columns 3,2 then 1
样例filename.txt
:
a b c
1 2 5
样例输出:
b , a
2 , 1
with-current-buffer
而不是save-excursion
和set-buffer
。 - pheaver