in reply to Perl One Liner Regular Expressions

Stallion,

Put your contents in monks.txt and give the following one liner.

perl -p -i -e "s/^macros(.)*/macros\ regex/g" monks.txt

:-)

Replies are listed 'Best First'.
Re^2: Perl One Liner Regular Expressions
by hbm (Hermit) on Aug 16, 2012 at 13:32 UTC

    No need for parentheses; nor to escape the space; nor for the 'g' modifier - '.*' will gobble everything up, thus there can be only one match. So:

    perl -p -i -e "s/^macros.*/macros regex/" monks.txt # or perl -p -i -e "s/^macros\K.*/ regex/" monks.txt
Re^2: Perl One Liner Regular Expressions
by cheekuperl (Monk) on Aug 16, 2012 at 13:20 UTC
    The grouping is not really required. This works pretty fine:
    s/^macros.*/macros regex/