Tran Ngu Dang
Tran Ngu Dang

Reputation: 2650

Get a number from a String using sed and regular expression

I have a string:

abc = "2342"

or: any string = "any number"

I wanna have a return value of 2342 (or any number)

How can I do it (using SED would be the best)

Upvotes: 0

Views: 93

Answers (1)

Max Nanasy
Max Nanasy

Reputation: 6141

sed 's/^[^=]*= *"\([^"]*\)"$/\1/'

or

sed -E 's/^[^=]*= *"([^"]*)"$/\1/'

Assumptions:

  • Any non-'=' can appear to the left of the '='
  • Any character (not just digits) can appear between the '"'s
  • Only ' 's between the '=' and the first '"'
  • No characters after the second '"'

Upvotes: 2

Related Questions