I am tring to write sed command to find and replace a key=value in a comma delimited string.
Example string in file: KEY_1=value_1,KEY_2=value_2,SOMEKEY=lastValue
The sed command used:
sed -r 's/KEY_2=.*?((?=,)|$)/KEY_2=new_value/' myFile.txt
If the Key exists replace it and its value with a new key=value. Most of the values will end with a comma ',' however the outlying case is the last key=value in the string will not have a ,.
Its giving me the following error message on RedHat Linux VM
sed: -e expression #1, char 55: Invalid preceding regular expression
which I believe is the last '/' I tried /g which would also be excptable as no key should be duplicated in the original string.
sed
does not support PCRE. – Kusalananda Sep 26 '18 at 06:34