Last active
April 8, 2019 19:29
-
-
Save pcapriotti/0fa8e11b240f268f3cfe7302c5553df7 to your computer and use it in GitHub Desktop.
Extract next link from HTTP header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Extract the "next" link from an HTTP response | |
sed ' | |
1,/^\r\{0,1\}$/ { | |
/^Link:/ !d | |
s/^Link: \(.*\)$/\1/ | |
}' | | |
{ | |
IFS= read -r links | |
url=$(jq -rn --arg links "$links" ' | |
@text "\($links)" | |
| split(", ") | |
| map( split("; ") | |
| { key: .[1] | split("\"") | .[1] , value: .[0] }) | |
| from_entries | |
| .next | |
| if . == null then "" else tostring end | |
| match("<(.*)>") | |
| .captures | .[0].string | |
') | |
echo "$url" | |
cat | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment