Skip to content

Instantly share code, notes, and snippets.

@hornc
Created November 30, 2021 01:42
Show Gist options
  • Save hornc/5d52510c444874df9ef86bc957113306 to your computer and use it in GitHub Desktop.
Save hornc/5d52510c444874df9ef86bc957113306 to your computer and use it in GitHub Desktop.
Takes an input list of ISBN13s and counts how many belong to each of the possible regional agencies.
#!/bin/bash
# Takes an input file argument (a sorted list of ISBN13s)
# and counts how many ISBNs are present belonging to each
# regional agency as listed in the official
# ISBN export_rangemessage.xml data.
wget -nc https://www.isbn-international.org/export_rangemessage.xml
while read prefix agency; do
echo -e "${agency}\t$(egrep -c ^$prefix $1)"
done < <(fgrep -A1 'Prefix' export_rangemessage.xml |
sed 's/<[^>]*>//g;s/-//g;s/^$/--/;s/^\s*/\t/' |
tr -d '\n' |
sed 's/$/--/;s/--/\n/g' |
sed -n 's/^\s//;/9780/,/ALL/p')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment