0

The string I need to modify in a hardware driver .conf file is as follows:

options rsi_sdio dev_oper_mode=13

Looks simple enough, but the developers are happy to change this string which will break a sed expression that matches with precision. I now have to treat the string preceeding the value as "indeterminate"; it cannot be reliably predicted with 100% precision.

Therefore I can only match on the value itself, which can itself also variable: it's currently "13" but this could change in future. The only "known" is the value that I need to modify can be either 1 or 2 digits in length.

So I need a bullet-proof regex that can guarantee the value can be successfully set even if both the string and value change to avoid breakage!

0

This actually caused a huge break in wireless connectivity when the developers threw me this curve ball. Since it is a situation many folks could find themselves in, I'll post my solution:

sed -E -i 's/=[0-9]{1,2}$/=6/' /etc/modprobe.d/rs9113.conf

This matches on the equal sign followed by at least 1 digit, but up to 2 digits. So the string can change, and even the default value of "13" can change, but this regex should remain future proof.

Hope others dealing with this type of wide variability find this approach helpful to ensuring their scripts remain correct-

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.