G
G
GogenZZo2020-02-10 16:12:06
bash
GogenZZo, 2020-02-10 16:12:06

Preg match in bash like in php?

Hello, how to get this in a bash script?

There is a string
Str = lalchlch login - 79991234567, password durhfh4fj

At the output in variables
Login = 79991234567
Pass =

durhfh4fj

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AUser0, 2020-02-10
@GogenZZo

It can be like this:

Str="лялчлч логин - 79991234567, пароль durhfh4fj"
Login=`echo "$Str" | grep -Po "логин - \K[0-9]+"`
Pass=`echo "$Str" | grep -Po "пароль \K.+"`
echo "Login=$Login"
echo "Pass=$Pass"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question