diff options
author | Nicolas Williams <nico@cryptonector.com> | 2014-06-17 18:59:35 -0500 |
---|---|---|
committer | Nicolas Williams <nico@cryptonector.com> | 2014-06-17 18:59:35 -0500 |
commit | 0c762925b22de041c0a41b6092838c27a7454b52 (patch) | |
tree | 70ae40ecd809bb7fd3ce491999f5c796ff8505c6 | |
parent | ad520265501f59de2572042506727a77bd0bb7ac (diff) |
Add `-j` / `--join-output` option, similar to `-r`
Fix #215.
-rw-r--r-- | docs/content/3.manual/manual.yml | 4 | ||||
-rw-r--r-- | jq.1.prebuilt | 8 | ||||
-rw-r--r-- | main.c | 7 |
3 files changed, 17 insertions, 2 deletions
diff --git a/docs/content/3.manual/manual.yml b/docs/content/3.manual/manual.yml index 78132f48..2868bdda 100644 --- a/docs/content/3.manual/manual.yml +++ b/docs/content/3.manual/manual.yml @@ -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 diff --git a/jq.1.prebuilt b/jq.1.prebuilt index ce0f7d6d..b827ba64 100644 --- a/jq.1.prebuilt +++ b/jq.1.prebuilt @@ -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 @@ -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 . @@ -75,6 +75,8 @@ enum { FROM_FILE = 512, + RAW_NO_LF = 1024, + EXIT_STATUS = 8192, /* debugging only */ @@ -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); } @@ -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")) { |