i want a way to extract 2 instances of digits following 2 different strings out of a long line of text produced from cURL http://website.com/.

So in this example output i want to grab both 23 and 144 and save them as different variables.

"AAABBBCCC" "Green":23',"AAABBBCCCCDDD" "Blue":144,"AAABBCCCDDDEEE" "Yellow":2,"

Can anyone make any suggestions?


I would extract all the numbers with grep and read the first two:

{ read first; read second; } < <(curl "$url" | grep -Eo '[0-9]+')
| improve this answer | |
  • The output can vary, so is it possible to look for a specific string such as "Green": and pull the following digits only? – Don Draper Jun 1 '18 at 10:03
  • 1
    Please edit your question and put all your requirements there. – glenn jackman Jun 1 '18 at 14:35
output=$(curl http://website.com/)

Your answers are in var1 and var2. I'm guessing the ' after the 23 was probably a typo.

| improve this answer | |
  • Ah yes the ' was a typo. – Don Draper Jun 1 '18 at 10:03
  • I have changed my solution in response. – dg99 Jun 1 '18 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.