I have a file that has several lines like:
"key1":"val1","key2":"val2","key3":"val3","key4":"val4"
In the vi
editor or using sed
I want to replace all the text between ":"
and ","
with ","
, i.e. I want to keep all keys and remove all the values.
The line will become like:
"key1","key2","key3","key4"
In vi
editor I tried to use :%s/":".*","/","/g
, and using sed
I used sed 's/":"*","/","/'
but instead of replacing the in-between text, it is removing all the text from the first occurrence of ":"
and last occurrence ","
,i.e. the line is becoming "key1","key4":"val4"
.
How do I replace the text in-between subsequent occurrences of ":"
and following ","
?