0

I need to go through thousands of files and find lines that start with

# disabledRule:

On these lines I need to look for a series of keywords, namely fileinto or fileinto_copy followed by create and target. Examples:

{s:4:"type";s:8:"fileinto";s:6:"create";b:0;s:6:"target";s:5:"PATTERN";}
{s:4:"type";s:13:"fileinto_copy";s:6:"create";b:0;s:6:"target";s:5:"PATTERN";}

After those keywords I need to modify the PATTERN and replace . with /.

PATTERN can consist of almost any character e.g.

simple.folder.structure
more.complex.[department_1] @employee-XY

The parts between the keywords can vary slightly and the whole "keywords+PATTERN" pattern can occur multiple times in one line.

It sounds easy but I couldn't figure out a way to make it work with sed/awk without writing a big script and take apart the lines. I think I'm half decent with sed to replace stuff and also to find patterns, but I don't know how to limit the replacement to only the PATTERN.

Any suggestions in what I could use to do this, without writing a longer script? Is there maybe a way with sed capture groups?

Update: As some may have figured out, the files need to be modified because of a migration. We knew that the new software is not fully compatible but as it turns out the above mentioned lines "# disabledRule" are not recognised by the new software at all, hence rendering the problem unsolvable from this perspective.

2
  • Welcome, could you give a real example of PATTERN? edit the question, don't add it in the comments. – schrodigerscatcuriosity Feb 18 at 18:14
  • There are no other . in the key-pairs. It's just the sample, or there could be? – schrodigerscatcuriosity Feb 18 at 18:23

Your Answer

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

Browse other questions tagged or ask your own question.