On Thursday, 1 November 2018 23:58:59 CET John Harmon wrote:
> I have been thinking about doing this with lineinfile with backrefs, or
> with the replace module, but I am at a loss as to where to start (I am
> horrible with regexp....)
>
> Consider the following:
> vif = ['mac=00:21:f6:A1:B7:49,bridge=1053d3f53c']
>
> I would like to replace the last three octets, but leave everything else
> alone:
> ie
> vif = ['mac=00:21:f6:*AA:BB:CC*,bridge=1053d3f53c']
>
> I am using a regexp tester, but am not getting the results I would like. Is
> regexp the right way to tackle this? Is there another/better way? If the
> former, I could use some regexp help. Thanks in advance.
Brad gave you a sed way, with lineinfile it would look something like this
- lineinfile:
path: /path/to/file
backrefs: yes
regexp: ^(vif = \['mac=)((\w{2}:){3})((\w{2}:?){3})(.+)$
line: \1\2AA:BB:CC\6
--
Kai Stian Olstad