'jq: replache slash by dash chracter

I need to replace slash character by "-".

I mean:

[
  "1934/08/20",
  "1961/01/10",
  "1952/01/25",
  "1967/07/24"
]

I need:

[
  "1934-0820",
  "1961-01-10",
  "1952-01-25",
  "1967-07-24"
]

Is there anyway to get it?

jq


Solution 1:[1]

Since you want to replace all the / with -'s, gsub is the way to go:

jq 'map(gsub("\/"; "-"))'

Will produce

[
  "1934-08-20",
  "1961-01-10",
  "1952-01-25",
  "1967-07-24"
]

As you can test in this online demo

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 0stone0