I want to remove , from a string in jq. Take the following example, how to remove , when outputting 1,2?
$ jq -r .x <<< '{"x":"1,2"}'
1,2
You can use sub.
Filter
.x | sub(","; " ")
Input
{"x":"1,2"}
Output
1 2
Demo
https://jqplay.org/s/IaViogZTsI
You didn't make clear what output you wanted. A literal reading suggests you want 12, but I find it more likely that you want each of the comma-separated items to be output on separate lines. The following achieves this:
jq -r '.x | split( "," )[]'
For the provided input, this outputs
1
2
Demo on jqplay
But if 12 is indeed what's desired, adding a join will do the trick.
jq -r '.x | split( "," ) | join( "" )'
12
Demo on jqplay
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With