0

I've below string, I would like to get 2563 from the below string using shell script.

Could you please help, how to get the number which is after request id

"requested producer access with request id 2563 to product exampledomain.test-dev.test.nonprod.com for user : test-user on product test-product-validation-required"

3 Answers 3

2

Assuming the string is stored in a variable $s.

Is it the only number? Then

grep -Eo '[[:digit:]]+' <<< "$s"

would work.

Or using a Bash regex:

re='request id ([[:digit:]]+)'
[[ $s =~ $re ]]
echo "${BASH_REMATCH[1]}"
Sign up to request clarification or add additional context in comments.

Comments

1

You need to use grep -oE '[0-9]*' on string, like:

data="requested producer access with request id 2563 to product exampledomain.test-dev.test.nonprod.com for user : test-user on product test-product-validation-required"

echo $data | grep -oE '[0-9]*'

Output: 2563

Comments

0
id=$(awk -F" id | to " '{gsub(/ /,"", $2); print $2}' <<<$string)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.