I'm trying to extract data from a .config file (generated by using kconfig). The default format is:
SYMBOL=y (in case of a bool)
SYMBOL="str" (in case of a string)
I did managed to get it working with the following regex:
sed -e '/^#/d;s/\(.+\)=\(.+\)/def \1 "\1"\n/g' configfile > formattedfile
It is working for any case except for this one:
SYMBOL="http://my.domain/toast?id=150"
As a result, I have in my output file:
def SYMBOL="http://my.domain/toast?id "SYMBOL="http://my.domain/toast?id="
Because the pattern XXX=XXX appears twice in this line. How can I avoid this please ?
Regards,
You need to escape the + symbol and also turn the first .+ to [^=]\+ because .+ is greedy and matches upto the last = symbol.
$ sed -e '/^#/d;s/\([^=]\+\)=\(.\+\)/def \1 "\1"\n/g' file
def SYMBOL "SYMBOL"
def SYMBOL "SYMBOL"
def SYMBOL "SYMBOL"
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