regex - Replace string in all files if surroundings match expectations -


i have 3rd party software (a php application in case) creates , sets file acces rights on code. dev reasons want them set 0777.

what got:

grep --include \*.php -rnp '[,=>]{1,2}\s*(0[67][0-6]{2})\s*[,;)]' * 2>/dev/null 

will return

engine/library/zend/cache/backend/file.php:104:           'hashed_directory_perm' => 0700, engine/library/zend/cache/backend/file.php:106:        'cache_file_perm' => 0600, recovery/common/vendor/knplabs/gaufrette/src/gaufrette/stream/local.php:36:            @mkdir($basedirpath, 0755, true); vendor/doctrine/common/lib/doctrine/common/proxy/proxygenerator.php:305:        chmod($tmpfilename, 0664);     vendor/doctrine/orm/lib/doctrine/orm/tools/entityrepositorygenerator.php:155:            chmod($path, 0664); vendor/doctrine/orm/lib/doctrine/orm/tools/export/driver/abstractexporter.php:148:                chmod($path, 0664); vendor/doctrine/orm/lib/doctrine/orm/tools/entitygenerator.php:392:        chmod($path, 0664); vendor/doctrine/orm/lib/doctrine/orm/cache/region/filelockregion.php:245:        chmod($filename, 0664); vendor/league/flysystem/src/adapter/local.php:33:            'public' => 0744, vendor/league/flysystem/src/adapter/local.php:34:            'private' => 0700, 

now @ point found files , places need adapt, have no idea how replace numbers.

any appreciated.

you can use -l option in grep , pipe xargs sed:

grep --include \*.php -rlp '[,=>]{1,2}\s*(0[67][0-6]{2})\s*[,;)]' * 2>/dev/null | xargs -i {} sed -i.bak 's/0[67][0-6][0-6]/0777/g' {} 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -