I have an s3 route and I have to split it in bucket, prefix and key using JQ.
"s3://bucket/folder1/folder2/folder3/key.txt" ->
{
bucket: bucket,
prefix: folder1/folder2/folder3,
key: key.txt
}
I have an s3 route and I have to split it in bucket, prefix and key using JQ.
"s3://bucket/folder1/folder2/folder3/key.txt" ->
{
bucket: bucket,
prefix: folder1/folder2/folder3,
key: key.txt
}
2
Answers
Quick / manual solution:
If you
split
on both//
and/
you can use$foo[0]
to get the bucket, use$foo[-1]
for the key (last index) andjoin
the rest (1:-1
) to get the prefix.Demo
Using regex capturing should do the trick while addressing any concerns regarding the use of
split
; e.g. with your inputproduces valid JSON: