Occasionally I use AWK to extract and/or reverse columns in a data file.
awk '{print $2,",",$1}' filename.txt
How would I do the same using 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
Sample filename.txt
:
a b c
1 2 5
Sample output:
b , a
2 , 1