Skip to content

Commit

Permalink
Add -j / --join-output option, similar to -r
Browse files Browse the repository at this point in the history
  • Loading branch information
nicowilliams committed Jun 17, 2014
1 parent ad52026 commit 0c76292
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/content/3.manual/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ sections:
formatted as a JSON string with quotes. This can be useful for
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`:
Read filter from the file rather than from a command line, like
Expand Down
8 changes: 7 additions & 1 deletion jq.1.prebuilt
Original file line number Diff line number Diff line change
Expand Up @@ -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\.
.
.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:
.
.IP
Expand Down Expand Up @@ -1937,7 +1943,7 @@ jq \'\.foo += 1\'
.IP "" 0
.
.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
.
Expand Down
7 changes: 6 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ enum {

FROM_FILE = 512,

RAW_NO_LF = 1024,

EXIT_STATUS = 8192,

/* debugging only */
Expand Down Expand Up @@ -111,7 +113,8 @@ static int process(jq_state *jq, jv value, int flags) {
ret = 0;
jv_dump(result, dumpopts);
}
printf("\n");
if (!(options & RAW_NO_LF))
printf("\n");
if (options & UNBUFFERED_OUTPUT)
fflush(stdout);
}
Expand Down Expand Up @@ -205,6 +208,8 @@ int main(int argc, char* argv[]) {
options |= PROVIDE_NULL;
} else if (isoption(argv[i], 'f', "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")) {
options |= EXIT_STATUS;
} else if (isoption(argv[i], 0, "arg")) {
Expand Down

0 comments on commit 0c76292

Please sign in to comment.