meallhour
meallhour

Reputation: 15581

Strip a particular word from the beginning of string in jq output

I am getting list of values as below using the curl command:

curl -s http://internal.registry.com/v2/_catalog | jq -r '.repositories[0:5] | to_entries | map( .value )[]'

Output:

centos
containersol/consul-server
containersol/mesos-agent
containersol/mesos-master
cybs/address-api

I want to make sure that output should not have the prefix cybs/ in it. for example, cybs/address-api should just be address-api

Upvotes: 3

Views: 5221

Answers (1)

Andreas Louv
Andreas Louv

Reputation: 47099

Just use sub:

curl ... | jq -r '.repositories[0:5][] | sub("^cybs/"; "")'

Also note that to_entries | map( .value ) is a NOP and should be removed.

Output:

centos
containersol/consul-server
containersol/mesos-agent
containersol/mesos-master
address-api

Upvotes: 10

Related Questions