You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently wrote a script which selects specific records and thought it would be nice to print a message for the user indicating how many matching records had been found. However, I was not able to find a way to produce raw output which was not sent to stdout (and therefore included in the script's normal output).
Effectively, I was hoping for something like the following:
The closest match for magic_output_function I could find was stderr | empty, which unfortunately prints its output as a JSON-formatted string, making it unsuitable for user-friendly output.
Requested feature
Ideally, I'd love to see a function which could send arbitrary output to arbitrary file descriptors. For example:
write_fd(fd)
The write_fd function writes a string from its input to the specified file descriptor. The only valid input is a single string, which is written in raw fashion. Note that file descriptor 1 (stdout) is where jq's normal output is sent.
This function could then be combined with any number of existing jq features to create any form of output desired, even duplicating the behavior of debug/0 and stderr/0.
# Write any value to stderr as a complete line, producing no results.defprintln: "\(.)\n"|write_fd(2);
# Log a value to an extra file descriptor, which the user can redirect to wherever they like. The input# is also the result, so that logging may be inserted into a pipelinedeflog: ("\(tojson)\n"|write_fd(4)), .;
# Log all input elements as a JSON stream and print the number of selected elements before writing output.
[ .[] |log|select(.accountName== ("\(.firstName).\(.lastName)"|ascii_downcase)) ]
| ("Found \(length) match(es)."|println), .
The text was updated successfully, but these errors were encountered:
The stderr filter now prints the string in raw format since the manual states it should do so (fixed by #2751). The proposed solution is an unportable and very complex way of solving the issue, and we will unlikely to implement such feature. Print log messages to standard error, and filter the output if you need.
While I do still think a more general output function would be handy, having raw output from stderr certainly covers all the actual use cases I have (and, I would expect, nearly all reasonable use cases).
Many thanks for the change! I'll anticipate 1.7 eagerly.
Use case
I recently wrote a script which selects specific records and thought it would be nice to print a message for the user indicating how many matching records had been found. However, I was not able to find a way to produce raw output which was not sent to stdout (and therefore included in the script's normal output).
Effectively, I was hoping for something like the following:
The closest match for
magic_output_function
I could find wasstderr | empty
, which unfortunately prints its output as a JSON-formatted string, making it unsuitable for user-friendly output.Requested feature
Ideally, I'd love to see a function which could send arbitrary output to arbitrary file descriptors. For example:
The
write_fd
function writes a string from its input to the specified file descriptor. The only valid input is a single string, which is written in raw fashion. Note that file descriptor 1 (stdout) is where jq's normal output is sent.This function could then be combined with any number of existing jq features to create any form of output desired, even duplicating the behavior of debug/0 and stderr/0.
The text was updated successfully, but these errors were encountered: