Add filename/line functions to jq (fix #753)
This adds `input_filename` and `input_line_number` built-in functions
for use in, for example, `error` messages.
Example:
$ printf '{"a":1}\n{"a":2}\n' > 4.json
$ printf '{"a":"hello"}\n' > 5.json
$ ./jq '{ "file":input_filename, "line":input_line_number, "value":.a }' 4.json 5.json
{
"file": "4.json",
"line": 1,
"value": 1
}
{
"file": "4.json",
"line": 2,
"value": 2
}
{
"file": "5.json",
"line": 1,
"value": "hello"
}
This commit is contained in:
1 parent
c7f063188f
commit
d1cb8ee0ad
5 files changed
+53
No files matched your search
@@ -2413,6 +2413,17 @@ sections:
|
||||
`["DEBUG:", <input-value>]` and prints that and a newline on
|
||||
stderr, compactly. This may change in the future.
|
||||
|
||||
- title: "`input_filename`"
|
||||
body: |
|
||||
|
||||
Returns the name of the file whose input is currently being
|
||||
filtered.
|
||||
|
||||
- title: "`input_line_number`"
|
||||
body: |
|
||||
|
||||
Returns the line number of the input currently being filtered.
|
||||
|
||||
- title: Assignment
|
||||
body: |
|
||||
|
||||
|
||||
Reference in new issue
Block a user