Created
November 9, 2024 11:06
-
-
Save sasasin/75f4fb34b03165ac7c759f4af1ab7055 to your computer and use it in GitHub Desktop.
某出版社の電子書籍ISBN13桁から紙書籍ISBN13桁を算出するAWKスクリプト
This file contains 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
# ISBN 13 桁版チェックディジット計算方法 は https://www.jbpa.or.jp/nenshi/pdf/0208.pdf を参考にした | |
{ | |
# ISBN を stdin から受け取る | |
isbn=$1; | |
# 電子書籍の ISBN から -10 して 13桁目を再計算した値が、紙書籍の ISBN | |
isbn = isbn - 10; | |
isbn_tmp = \ | |
((substr(isbn, 1, 1) + substr(isbn, 3, 1) + substr(isbn, 5, 1) + substr(isbn, 7, 1) + substr(isbn, 9, 1) + substr(isbn, 11, 1)) * 1) + \ | |
((substr(isbn, 2, 1) + substr(isbn, 4, 1) + substr(isbn, 6, 1) + substr(isbn, 8, 1) + substr(isbn, 10, 1) + substr(isbn, 12, 1)) * 3); | |
isbn_chk_digit = 10 - (isbn_tmp % 10); | |
# 求めた下1桁が0の場合はチェック数字を0とする | |
if ((isbn_chk_digit % 10) == 0) { | |
isbn_chk_digit = 0; | |
} | |
print substr(isbn, 1, 12) isbn_chk_digit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment