Reputation: 544
Regex pattern to search all recurences in string.
Ex- echo '%%MYSQL_PORT%%=%%3356%%' | grep \%%.*\%%
Actual output- %%MYSQL_PORT%%=%%3356%%
Expected output- %%MYSQL_PORT%% %%3356%%
Upvotes: 1
Views: 200
Reputation: 627101
You may use
echo '%%MYSQL_PORT%%=%%3356%%' | grep -o '%%[^%]*%%'
See the online demo
You need -o
option to output the matches only and you should replace .*
with [^%]*
that will only match 0 or more chars other than %
char.
Output:
%%MYSQL_PORT%%
%%3356%%
Upvotes: 2