-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed as not planned
Description
I would like to propose a new builtin, say output_file("filename"; "contents"), which copies its input to its output while saving its arguments as a file. It's similar in principle to the debug builtin.
If --sandbox is specified, it will simply output the filename to stderr, essentially acting as a dry run.
Having this builtin would make it less awkward to split json files. See below for some workarounds that are currently required:
- Output to multiple files #2438
- Create Multi Smaller Files From a Big Json File #3121
- https://stackoverflow.com/questions/70569726/jq-split-json-in-several-files
Proposed semantics:
# sample script
to_entries[] | output_file(.key; .value) | .key
# stdin
{
"a.txt": "string\nstring",
"b/c.txt": "invalid",
"d.json": {
"e": 10
}
}
# stdout
"a.txt"
"b/c.txt"
"d.json"
# stderr
b/c.txt: No such file or directory
# a.txt
string
string
# d.json
{"e":10}tianon
Metadata
Metadata
Assignees
Labels
No labels