sup*_*ize 19 shell io-redirection
如何编写通过jqshell发送到文件的管道输出
例:
curl api.example.com | jq > call.txt
Run Code Online (Sandbox Code Playgroud)
不行.也没有
(curl api.example.com | jq) > call.txt
Run Code Online (Sandbox Code Playgroud)
救命!
编辑:所以做得curl api.example.com > call.txt很好.所以它与管道到jq有关
Att*_*tie 28
你使用jq错了......
stdout如果jq '.'不是终端,只是调用会抛出错误
$ curl https://jsonplaceholder.typicode.com/posts/1 | jq > test.txt
jq - commandline JSON processor [version 1.5-1-a5b5cbe]
Usage: jq [options] <jq filter> [file...]
jq is a tool for processing JSON inputs, applying the
given filter to its JSON text inputs and producing the
[...]
Run Code Online (Sandbox Code Playgroud)
尝试man jq(即:漂亮打印输入JSON):
$ curl https://jsonplaceholder.typicode.com/posts/1 | jq '.' > test.txt
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 292 100 292 0 0 1698 0 --:--:-- --:--:-- --:--:-- 1707
Run Code Online (Sandbox Code Playgroud)
请注意,过滤器不是真正可选的:
来自jq:
JQ(1) JQ(1)
NAME
jq - Command-line JSON processor
SYNOPSIS
jq [options...] filter [files...]
Run Code Online (Sandbox Code Playgroud)
根据主分支的提示......你所描述的(以及我观察到的)行为是不可预期的......
旧版本stdout具有以下内容:( 此处)
if (!program && isatty(STDOUT_FILENO) && !isatty(STDIN_FILENO))
program = ".";
Run Code Online (Sandbox Code Playgroud)
即:如果stdin 是 TTY,则使用默认过滤器,而jq 不是 TTY.
此行为似乎在提交5fe05367中得到纠正,使用以下代码片段:
if (!program && (!isatty(STDOUT_FILENO) || !isatty(STDIN_FILENO)))
program = ".";
Run Code Online (Sandbox Code Playgroud)
Jar*_*kus 16
我的咒语:
$ cat config.json
{
"ProgramSettings":
{
"version": "1.0"
},
"ProgramSecrets":
{
"AWS_ACCESS_KEY_ID": "",
"AWS_SECRET_ACCESS_KEY": ""
}
}
Run Code Online (Sandbox Code Playgroud)
假设您想从 JSON 文件中删除对象“ProgramSecrets”:
$ echo $(cat config.json | jq 'del(.ProgramSecrets)') > config.json
$ cat config.json
{ "ProgramSettings": { "version": "1.0" } }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16543 次 |
| 最近记录: |