Created
March 26, 2023 16:13
-
-
Save fuse/59e110473bb37413a84f9e849114e83e to your computer and use it in GitHub Desktop.
After merging two 1password vaults I ended up with a lot of duplicates. I wanted to only keep one version of each entry.
This file contains hidden or 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 | |
# This script basically find duplicateds based on titles, keep the first one and delete the other ones. | |
# /!\ Be careful if you have different IDs that potentially have the same title. | |
# You need 1password client and jq to make it work | |
json_data=$(op item list --format json) | |
duplicates=$(echo "$json_data" | jq -r '.[] | .title' | sort | uniq -d) | |
while read -r title; do | |
ids=$(echo "$json_data" | jq --arg title "$title" -r '.[] | select(.title == $title) | .id' | tr '\n' ' ') | |
# Shift first id | |
first_id=$(echo "$ids" | cut -d ' ' -f1) | |
# Delete the other ones | |
for item in $(echo "$ids" | cut -d ' ' -f2-); do | |
echo "Deleting $item for $titre" | |
op item delete $item | |
done | |
done <<<"$duplicates" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment