Skip to content

Instantly share code, notes, and snippets.

@flannon
Last active July 18, 2018 06:27
Show Gist options
  • Save flannon/103a6dc6bb31721ec8dccbe44e1caf1b to your computer and use it in GitHub Desktop.
Save flannon/103a6dc6bb31721ec8dccbe44e1caf1b to your computer and use it in GitHub Desktop.
Jq notes
Show names and ids of all efs file systems
$ aws efs describe-file-systems | jq '.FileSystems[] | {FileSystems: .Name, FileSystemId}'
Select a single file system based on its name tag,
$ aws efs describe-file-systems | jq '.FileSystems[] | select(.Name == "my_fs_name")'
Using two select statements for two fields returns two identical records (?)
aws efs describe-file-systems | jq '.FileSystems[] | select(.Name | contains("my_fs_name")), select(.FileSystemId | contains("fs-00000000"))'
Return the fs record only if both fields match,
$ aws efs describe-file-systems | jq '.FileSystems[] | select(.Name == "my_fs_name") | select(.FileSystemId | contains("fs-00000000"))?'
Doing it with grep and awk
- $aws efs describe-file-systems | jq '.FileSystems[] | select(.Name == "my_fs_name")' | grep FileSystemId | awk -F':' '{print $2}' | awk -F"\"" '{print $2}'
Only return a value if both the file system name and the file system id match the given values,
- $ aws efs describe-file-systems | jq '.FileSystems[] | select(.Name == "my_fs_name")' | jq '. | select(.FileSystemId == "fs-000000000")'
Show just the filesystem if,
- $ FSID=$( aws efs describe-file-systems | jq '.FileSystems[] | select(.Name == "my_ef_name")' | jq '. | .FileSystemId')
- $ echo ${FSID:1:11}
Or just do it with sed,
- $ FSID=$(aws efs describe-file-systems | jq '.FileSystems[] | select(.Name == "my_ef_name")' | jq '. | .FileSystemId' | sed -e s/\"//g)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment