'Is there a way to combine columns from cli output? [closed]

I want to get memorydb endpoint URL in the format (address:port). When I run the aws cli command aws memorydb describe-clusters --cluster-name xxx --query 'Clusters[0].ClusterEndpoint' --output text, I get the output as (address port).

I want to get it in the format (address:port). Is there a command i can use to add ':' to combine address and port number.

Thanks



Solution 1:[1]

Assuming you have set your variable to the string which you posted, i.e.

x='(address port)'

you can calculate using parameter expansion

y=${x/ /:}

which substitutes the first space by a colon and gives you on y the value (address:port).

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