3 ms·
TXR Lisp, using standard awk macro: (awk (:inputs *stdin*) (:set fs "," ofs ",")
by kazinator 9y ago
TXR Lisp, using standard awk macro:
(awk (:inputs *stdin*)
(:set fs "," ofs ",")
(:let pos (name [*args* 0]) (rplc [*args* 1]))
((= nr 1) (set pos (pos name f)))
((> nr 1) (set [f pos] rplc))
(t (prn)))
Missing args -> pass through:
$ txr solve.tl < data
name,surname,city,country
Adam,Jones,Manchester,UK
Joe,Doe,Cracow,Poland
Michael,Smith,Paris,France
Alex,McNeil,Gdynia,Poland
With args:
$ txr solve.tl city London < data
name,surname,city,country
Adam,Jones,London,UK
Joe,Doe,London,Poland
Michael,Smith,London,France
Alex,McNeil,London,Poland
We need (:inputs stdin) so that awk takes its input from standard input rather than processing the city London arguments as input sources.