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

Viraj Deshpande
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 188 100 188 0 0 180 0 0:00:01 0:00:01 --:--:--
180{"result":{"fileId":"3a29ca7a-813a-4b3b-9b9c-
6f9251d2171d","percentComplete":100.0,"status":"complete"},"meta":{"requestId":"*************************************************************************","httpStatus":"200 - OK"}}

Again - I need to extract the highlighted part that follows "fileId":

I tried using the following -

VAR2="$(curl <...> | sed -E -n 's/.*fileId":"([^"]+).+/\2/p')"

But when I run echo $VAR2 I do not get any output

p.s. ideally I want this to happen only when percentComplete:100.0 (but this is not a priority, extracting the fileId is the priority for now)

Francesco Lucianò

This should work:

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

The problem with your try is that you used \2 in the sed command, but you only have one regex group. I think you should take a look at the sed info page to understand how sed works.

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?

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 can I assign Cell Part as Variable?

From Dev

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

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

Extract part of a curl return in Bash to allocate to a variable

From Dev

How Can I Expand A Tilde ~ As Part Of A Variable?

From Dev

Can I display specific part of Output from Command Prompt in Windows?

From Dev

Error when substituting part of curl command with variable

From Dev

Why is shell treating a part of the output of $(<file) as a command?

From Dev

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

From Dev

How do I get a part of the output of a command in Linux Bash?

From Dev

How can I format output of shell command

From Dev

How can I extract the part that is after @ in an email using php?

From Dev

How to log output of a part of a shell script

From Dev

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

From Dev

Extract part of a variable in batch

From Dev

How do I "assign" a part of a disk to a folder?

From Dev

How can I put a variable in this part of my code?

From Dev

How can I substitute part of a variable using random inputs?

From Dev

How to output a shell command into a variable?

From Dev

js: can I assign a class or an id to an html-element that's part of a variable definition?

From Dev

How can I extract 2 pieces of information output from command though pipes in a bash script?

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 pass an environment variable as a part of a 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

Related Related

  1. 1

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

  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 can I assign Cell Part as Variable?

  5. 5

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

  6. 6

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

  7. 7

    Assign output of a shell command to a variable

  8. 8

    Extract part of a curl return in Bash to allocate to a variable

  9. 9

    How Can I Expand A Tilde ~ As Part Of A Variable?

  10. 10

    Can I display specific part of Output from Command Prompt in Windows?

  11. 11

    Error when substituting part of curl command with variable

  12. 12

    Why is shell treating a part of the output of $(<file) as a command?

  13. 13

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

  14. 14

    How do I get a part of the output of a command in Linux Bash?

  15. 15

    How can I format output of shell command

  16. 16

    How can I extract the part that is after @ in an email using php?

  17. 17

    How to log output of a part of a shell script

  18. 18

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

  19. 19

    Extract part of a variable in batch

  20. 20

    How do I "assign" a part of a disk to a folder?

  21. 21

    How can I put a variable in this part of my code?

  22. 22

    How can I substitute part of a variable using random inputs?

  23. 23

    How to output a shell command into a variable?

  24. 24

    js: can I assign a class or an id to an html-element that's part of a variable definition?

  25. 25

    How can I extract 2 pieces of information output from command though pipes in a bash script?

  26. 26

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

  27. 27

    How to pass an environment variable as a part of a command

  28. 28

    How to assign the output of calculation to a shell variable

  29. 29

    How can i assign half command to variable in bash

HotTag

Archive