search and replace using regular expression

phpmysqlcoder
phpmysqlcoder used Ask the Experts™
on
I ma using a code generator and trying to automate the search and replace of a string using bash script/Perl (linux)

Original
$RootMenu->AddMenuItem(10018, $Language->MenuPhrase("10018", "MenuText"), "serverlist.php", 10028, "", AllowListMenu('server'));
$RootMenu->AddMenuItem(28, $Language->MenuPhrase("28", "MenuText"), "userlist.php?cmd=resetall", 10028, "", AllowListMenu('user'));
$RootMenu->AddMenuItem(10027, $Language->MenuPhrase("10027", "MenuText"), "myadmin/index.php", 10028, "", IsLoggedIn());

Open in new window


revised (3rd line)
$RootMenu->AddMenuItem(10018, $Language->MenuPhrase("10018", "MenuText"), "serverlist.php", 10028, "", AllowListMenu('server'));
$RootMenu->AddMenuItem(28, $Language->MenuPhrase("28", "MenuText"), "userlist.php?cmd=resetall", 10028, "", AllowListMenu('user'));
$RootMenu->AddMenuItem(10027, $Language->MenuPhrase("10027", "MenuText"), "myadmin/index.php", 10028, "", AllowListMenu('server'));

Open in new window


How to achieve this?

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017

Commented:
s/^(.*)AllowListMenu('server')(.*)$/$1IsLoggedIn()$2/

You would need to setup something that will detect the criteria where this substitution is to occur.
if the input is menu.txt

perl -pne "/AddMenuItem\(10027/ && s/IsLoggedIn\(\)/AllowListMenu\('server'\)/;" menu.txt

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial