JQ выбрать подстроку из столбца - PullRequest
0 голосов
/ 11 февраля 2020

У меня есть файл test. json, содержащий следующее:

{
  "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"
    }
  ]
}

Я могу успешно сделать это:

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.

Однако, если я просто попытаюсь извлечь первые 250 символы столбца "short_description" я получаю следующую ошибку:

cat test.json|jq -r '.result[0:249].short_description'

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

Подскажите, пожалуйста, что я делаю не так?

Спасибо!

1 Ответ

2 голосов
/ 11 февраля 2020

Примените фильтр подстроки к строке "short_description":

jq -r '.result[].short_description[:250]' test.json
...