Sample Header Ad - 728x90

How can I call an external command from within Miller (mlr)’s DSL?

6 votes
1 answer
923 views
Suppose I have the following CSV:
$ cat test.csv
id,domain
1,foo.com
2,bar.com
Using mlr put, I can easily map any function over a field in the CSV, as long as I can define it in the Miller DSL . So, for example, mlr --csv put '$id = $id + 1' will increment the id by 1 for each record. But what if I can’t define the function in Miller’s DSL, perhaps because it is not pure? Suppose I wanted to map each domain in the CSV to an IP address. I’d like to do something like mlr --csv put '$ip = shell("nslookup $domain"). Is there an easy way to do this? Currently I am extracting the input field into a separate file, rewriting it in a separate shell script, and adding the result back in with mlr join. However, this is pretty messy, because my CSV is full of quoted commas and newlines, which I need to carefully handle myself rather than relying on Miller.
Asked by sjy (956 rep)
Jan 29, 2019, 08:12 AM
Last activity: Nov 28, 2020, 12:50 PM