How can I extract part of the output of a curl command and assign it to a shell variable?

Viraj Deshpande
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 277 100 174 100 103 464 274
--:--:-- --:--:-- --:--:--
736{"result":{"progressId":"ES_7PBXiq5gg67u9Vr","percentComplete":0.0,"status":"inProg
ress"},"meta":{"requestId":"**********************","httpStatus":"200 -
OK"}}

I need to extract the highlighted part beginning with ES_

I tried using

curl <...> | sed '"progressId"\:"(ES_[A-Za-z0-9]{15})'

however it still stores the entire output in the environment variable.

Francesco Lucianò

This should work:

curl <...> | sed -E -n 's/.*(ES[^"]+).+/\1/p'

Explanation:

  • .* means 'any char 0 or more times'
  • ES[^"]+ means 'ES followed by any char which is not " one or more times'
  • .+ means 'any char 1 or more times'
  • \1 means 'the first group', so what's inside ()
  • p means 'print only matching lines'

If you want to store it in a variable you can do it with backtick ` like this:

VAR="$(curl <...> | sed -E -n 's/.*(ES[^"]+).+/\1/p')"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I extract part of the output of a curl command and assign it to a shell variable - part 2?

From Dev

How can I assign the output of a command to a shell variable?

From Dev

How can I assign the output of this command to a variable in Shell?

From Dev

How to assign a variable the output of a shell command in Tupfile?

From Dev

Assign output of a shell command to a variable

From Dev

How can I assign Cell Part as Variable?

From Dev

How to assign the output of uniq command to a variable in shell script

From Dev

Assign part of a command's output to a variable in bash?

From Dev

How can I format output of shell command

From Dev

How do I assign the Output of a command as a Value of a variable?

From Dev

How to output a shell command into a variable?

From Dev

How do I pipe the output of a curl command to an environment variable and use it in another curl command?

From Dev

How to assign the output of calculation to a shell variable

From Dev

How can i assign half command to variable in bash

From Dev

How can I test the output of ant command in a Shell script?

From Dev

How can I loop over the output of a shell command?

From Dev

How can I pipe a command output to a CSV file in shell?

From Dev

Error while trying to assign output of a command to shell variable in SunOS

From Dev

curl command output in a variable

From Dev

How do I assign the output of a command to a variable without running the command in a subshell?

From Dev

Shell - how i can use a variable in sed command

From Dev

how to set an expect variable with output of shell command

From Dev

How do I add a variable to this curl command?

From Dev

How do I add a variable to this curl command?

From Dev

assign command output to variable in bash

From Dev

Unable to assign output of command to a variable

From Dev

Shell: how to extract the newest results from find command with multiple output?

From Java

How to do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)?

From Dev

How do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)?

Related Related

  1. 1

    How can I extract part of the output of a curl command and assign it to a shell variable - part 2?

  2. 2

    How can I assign the output of a command to a shell variable?

  3. 3

    How can I assign the output of this command to a variable in Shell?

  4. 4

    How to assign a variable the output of a shell command in Tupfile?

  5. 5

    Assign output of a shell command to a variable

  6. 6

    How can I assign Cell Part as Variable?

  7. 7

    How to assign the output of uniq command to a variable in shell script

  8. 8

    Assign part of a command's output to a variable in bash?

  9. 9

    How can I format output of shell command

  10. 10

    How do I assign the Output of a command as a Value of a variable?

  11. 11

    How to output a shell command into a variable?

  12. 12

    How do I pipe the output of a curl command to an environment variable and use it in another curl command?

  13. 13

    How to assign the output of calculation to a shell variable

  14. 14

    How can i assign half command to variable in bash

  15. 15

    How can I test the output of ant command in a Shell script?

  16. 16

    How can I loop over the output of a shell command?

  17. 17

    How can I pipe a command output to a CSV file in shell?

  18. 18

    Error while trying to assign output of a command to shell variable in SunOS

  19. 19

    curl command output in a variable

  20. 20

    How do I assign the output of a command to a variable without running the command in a subshell?

  21. 21

    Shell - how i can use a variable in sed command

  22. 22

    how to set an expect variable with output of shell command

  23. 23

    How do I add a variable to this curl command?

  24. 24

    How do I add a variable to this curl command?

  25. 25

    assign command output to variable in bash

  26. 26

    Unable to assign output of command to a variable

  27. 27

    Shell: how to extract the newest results from find command with multiple output?

  28. 28

    How to do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)?

  29. 29

    How do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)?

HotTag

Archive