I have been trying to extract part of a text (a header) for a long time in bash script
but I have not succeeded, this is what I have:
link: <https://api.some.com/v1/monitor/zzsomeLongIdzz?access_token=xxSomeLongTokenxx==>; rel="monitor",<https://api.some.com/v1/services/xx/something-more/accounts/2345?access_token=xxSomeLongTokenxx==>; rel="parent"
Here with a little format so you can see it better
link:
<https://api.some.com/v1/monitor/zzsomeLongIdzz?access_token=xxSomeLongTokenxx==>;
rel="monitor",
<https://api.some.com/v1/services/xx/something-more/accounts/2345?access_token=xxSomeLongTokenxx==>;
rel="parent"
I need the second part, just the url
, basically the values between ,<
and >; rel="parent"
and assign that to a variable, something like:
my_url = $(echo $complete_header) <== aplicarle alguna forma de filtro
I have no idea how to apply a pattern or regex to it to extract the data I need. Before I used jq
to filter json
, something like:
error_message=$(echo $response | jq '.["errors"]|.[0]|.["message"]')
Unfortunately for me this is not json
.
Can anyone help me go in the right direction to my question?
If the solution were with regex, I would like you to give me a summary of what said regex means, enough to be able to modify it.
I have put the header in a file
header
containing your example:Using
--only-matching
,--perl-regexp
and lookbehind and lookahead assertions ( Advanced Grep Topics ):Is obtained:
In your bash script:
I think for your specific case it could work very well.