1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Add -j / --join-output option, similar to -r

Fix #215.
This commit is contained in:
Nicolas Williams
2014-06-17 18:59:35 -05:00
parent ad52026550
commit 0c762925b2
3 changed files with 17 additions and 2 deletions

View File

@@ -152,6 +152,10 @@ sections:
formatted as a JSON string with quotes. This can be useful for formatted as a JSON string with quotes. This can be useful for
making jq filters talk to non-JSON-based systems. making jq filters talk to non-JSON-based systems.
* `--join-output` / `-j`:
Like `-r` but jq won't print a newline after each output.
* `-f filename` / `--from-file filename`: * `-f filename` / `--from-file filename`:
Read filter from the file rather than from a command line, like Read filter from the file rather than from a command line, like

View File

@@ -109,6 +109,12 @@ Output the fields of each object with the keys in sorted order\.
With this option, if the filter\'s result is a string then it will be written directly to standard output rather than being formatted as a JSON string with quotes\. This can be useful for making jq filters talk to non\-JSON\-based systems\. With this option, if the filter\'s result is a string then it will be written directly to standard output rather than being formatted as a JSON string with quotes\. This can be useful for making jq filters talk to non\-JSON\-based systems\.
. .
.IP "\(bu" 4 .IP "\(bu" 4
\fB\-\-join\-output\fR / \fB\-j\fR:
.
.IP
Like \fB\-r\fR but jq won\'t print a newline after each output\.
.
.IP "\(bu" 4
\fB\-f filename\fR / \fB\-\-from\-file filename\fR: \fB\-f filename\fR / \fB\-\-from\-file filename\fR:
. .
.IP .IP
@@ -1937,7 +1943,7 @@ jq \'\.foo += 1\'
.IP "" 0 .IP "" 0
. .
.SS "Complex assignments" .SS "Complex assignments"
Lots more things are allowed on the left\-hand side of a jq assignment than in most langauges\. We\'ve already seen simple field accesses on the left hand side, and it\'s no surprise that array accesses work just as well: Lots more things are allowed on the left\-hand side of a jq assignment than in most languages\. We\'ve already seen simple field accesses on the left hand side, and it\'s no surprise that array accesses work just as well:
. .
.IP "" 4 .IP "" 4
. .

5
main.c
View File

@@ -75,6 +75,8 @@ enum {
FROM_FILE = 512, FROM_FILE = 512,
RAW_NO_LF = 1024,
EXIT_STATUS = 8192, EXIT_STATUS = 8192,
/* debugging only */ /* debugging only */
@@ -111,6 +113,7 @@ static int process(jq_state *jq, jv value, int flags) {
ret = 0; ret = 0;
jv_dump(result, dumpopts); jv_dump(result, dumpopts);
} }
if (!(options & RAW_NO_LF))
printf("\n"); printf("\n");
if (options & UNBUFFERED_OUTPUT) if (options & UNBUFFERED_OUTPUT)
fflush(stdout); fflush(stdout);
@@ -205,6 +208,8 @@ int main(int argc, char* argv[]) {
options |= PROVIDE_NULL; options |= PROVIDE_NULL;
} else if (isoption(argv[i], 'f', "from-file")) { } else if (isoption(argv[i], 'f', "from-file")) {
options |= FROM_FILE; options |= FROM_FILE;
} else if (isoption(argv[i], 'j', "join-output")) {
options |= RAW_OUTPUT | RAW_NO_LF;
} else if (isoption(argv[i], 'e', "exit-status")) { } else if (isoption(argv[i], 'e', "exit-status")) {
options |= EXIT_STATUS; options |= EXIT_STATUS;
} else if (isoption(argv[i], 0, "arg")) { } else if (isoption(argv[i], 0, "arg")) {