awk '{print ,",}' 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 c1 2 5
样本输出:
b,a2,1解决方法 你打算如何使用它?您是否计划将其用作命令行脚本?在这种情况下,您需要像 hello world question一样打包它.
或者,您是否计划以交互方式使用它,在这种情况下,您可能希望将输出放在新缓冲区中…
这段代码完成了基础知识.您需要更新它以符合您的使用模式.
(defun awk (filename &rest cols) "Given a filename and at least once column,print out the column(s) valuesin the order in which the columns are specifIEd." (let* ((buf (find-file-noselect filename))) (with-current-buffer buf (while (< (point) (point-max)) (let ((things (split-string (buffer-substring (line-beginning-position) (line-end-position)))) (c cols) comma) (while c (if comma (print ",")) (print (nth (1- (car c)) things)) (setq comma t) (setq c (cdr c))) (print "\n") (forward-line)))) (kill-buffer buf)))总结
以上是内存溢出为你收集整理的在Emacs Lisp中awk'{print $2,“,”,$1}’?全部内容,希望文章能够帮你解决在Emacs Lisp中awk'{print $2,“,”,$1}’?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)