Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using sed with back-references calculated

I would like

pm.max_children = 5

to become;

pm.max_children = 8

and have been working on it and got no soludtions. Backreferences like \1 or \2 don’t seem to be working with calculation.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

sed -i -E "s/(pm.max_children)[^=]*=\s*(.+)/\1 = $(echo \2+3)/" /usr/local/etc/php-fpm.d/www.conf 

Using perl commands are OK as well as long as it is solved.

Thank you.

>Solution :

perl -i.bak -wpe's/pm.max_children\s*=\s*\K([0-9]+)/$1 + 3/e' file

This keeps a backup due to .bak; remove that (after testing) if you don’t need a backup.

The \K drops all previous matches so they are not consumed and don’t have to be restored in the replacement part.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading