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:
Assaf Gordon authored and Nicolas Williams committed 2015-05-21 00:49:32 -05:00
1 parent c7f063188f
commit d1cb8ee0ad
5 files changed
+53

No files matched your search

+11
View File
@@ -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: |