-1
% 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)

1 Answers1

0

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.

Francesco
  • 836