0

Example after using jq and jmespath:

i'm interested in objectId in the middle of the string... i tried to use sed, regex, but there must be some smart solution....

cmd 1:

az dls fs access show --account "$account" --path "$rootpath/$x" --output table --query "entries[? contains(@,'default:group')] | [1:6] " > ./output/"$x"_table.json

output (1 json object):

[
  "default:group:0d275816-7a1d-4847-884d-b5c67f473973:-wx",
  "default:group:106004df-6d49-450e-a180-e5bfa1fef9b3:r-x",
  "default:group:200a2bc4-feeb-4ab5-a4c1-3cc3752fe50e:r-x",
  "default:group:956041d5-49af-4409-a2b4-67c1cf2bc433:-wx"
]

in the next step I need to use these objectId's (956041d5-49af-4409-a2b4-67c1cf2bc433) as a input for another command, in the for loop...so, i need to save them into array or file...

in the pipe I can remove first part of the string:

sed s/"default:group:"//

Should i use default:group: as a some key in jq??? but how? isnt it better to use another pipe with sed with reg ex to delete ":-wx" from the string??



cmd 2

az dls fs access show --account "$account" --path "$rootpath/$x" > ./output/"$x".json

output example (Json without any filter):

{
  "entries": [
    "user::rwx",
    "user:9cad54de-ec93-4c11-aa3a-b84ce4c91920:rwx",
    "user:d494419c-01f7-4cf7-a5a4-142647853aac:rwx",
    "group::rwx",
    "group:0d275816-7a1d-4847-884d-b5c67f473973:-wx",
    "group:106004df-6d49-450e-a180-e5bfa1fef9b3:r-x",
    "group:5e36e3d9-1579-41fb-b621-3b5baec1e1f2:r-x",
    "group:83f994b9-167f-4886-a10a-63d145befd86:r-x",
    "group:a2adc59f-c1d4-4c48-8676-9d241aa8138c:-wx",
    "group:e4cded2e-6991-4259-bf4c-b93773b28a57:-wx",
    "mask::rwx",
    "other::---",
    "default:user::rwx",
    "default:user:9cad54de-ec93-4c11-aa3a-b84ce4c91920:rwx",
    "default:user:d494419c-01f7-4cf7-a5a4-142647853aac:rwx",
    "default:group::rwx",
    "default:group:0d275816-7a1d-4847-884d-b5c67f473973:-wx",
    "default:group:106004df-6d49-450e-a180-e5bfa1fef9b3:r-x",
    "default:group:5e36e3d9-1579-41fb-b621-3b5baec1e1f2:r-x",
    "default:group:83f994b9-167f-4886-a10a-63d145befd86:r-x",
    "default:group:a2adc59f-c1d4-4c48-8676-9d241aa8138c:-wx",
    "default:group:e4cded2e-6991-4259-bf4c-b93773b28a57:-wx",
    "default:mask::rwx",
    "default:other::---"
  ],
  "group": "1e682179-6809-4f88-8313-a399302b1b1a",
  "owner": "d494419c-01f7-4cf7-a5a4-142647853aac",
  "permission": "770",
  "stickyBit": false
}

1 Answers1

0

I need to use these objectId's

Given the array of strings as shown, the following jq filter produces the ids as shown below:

.[] | capture(".*group:(?<g>[^:]*):").g

Of course there are other ways to extract the objectIds, e.g. you could presumably simply split on ":":

.[] | split(":")[2]

Output

"0d275816-7a1d-4847-884d-b5c67f473973"
"106004df-6d49-450e-a180-e5bfa1fef9b3"
"200a2bc4-feeb-4ab5-a4c1-3cc3752fe50e"
"956041d5-49af-4409-a2b4-67c1cf2bc433"

peak
  • 105,803
  • 17
  • 152
  • 177