首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从列中选择子字符串

从列中选择子字符串
EN

Stack Overflow用户
提问于 2020-02-11 17:13:04
回答 1查看 1.3K关注 0票数 1

我有包含以下内容的文件test.json:

代码语言:javascript
运行
复制
{
  "result": [
    {
      "short_description": "The Net Energy Metering (NEM) Customer Application Database is used to track Customer Applications for a Net Energy Metering Interconnection Application. In almost all cases, the driver of these applications is prompted by the customer installing solar panels on the roof or his or her residence. There are numerous steps required in order to process the NEM applications. The Net Energy Metering Database facilitates this process and allows ACME to keep track of the current status of each customer application.",
      "managed_by": "Bill Anderson",
      "u_storm_impact_flag": "",
      "business_criticality": "Medium",
      "u_compliance_flag": "",
      "active": "true",
      "emergency_tier": "Tier 3"
    }
  ]
}

我可以成功做到这一点:

代码语言:javascript
运行
复制
cat test.json|jq -r '.result[].short_description'

The Net Energy Metering (NEM) Customer Application Database is used to track Customer Applications for a Net Energy Metering Interconnection Application. In almost all cases, the driver of these applications is prompted by the customer installing solar panels on the roof or his or her residence. There are numerous steps required in order to process the NEM applications. The Net Energy Metering Database facilitates this process and allows PHI to keep track of the current status of each customer application.

但是,如果我只是试图提取"short_description“列的前250个字符,则会得到以下错误:

代码语言:javascript
运行
复制
cat test.json|jq -r '.result[0:249].short_description'

jq: error (at <stdin>:13): Cannot index array with string "short_description"

你能告诉我我做错了什么吗?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-11 17:25:52

在"short_description“字符串上应用子字符串筛选器:

代码语言:javascript
运行
复制
jq -r '.result[].short_description[:250]' test.json
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60174153

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档