Last active
January 13, 2018 17:09
-
-
Save tacmasi/692581a2b5f4da4204310f79cb7ae4a9 to your computer and use it in GitHub Desktop.
カナは全角に,英数字は半角に(gawk) ref: https://qiita.com/tacmasi/items/f57d9a5252e0765ab2ad
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
$ gawk -V | |
GNU Awk 4.1.4, API: 1.1 (GNU MPFR 3.1.5, GNU MP 6.1.2) | |
(略) | |
$ echo " | |
|すき家|茨城県|すき家 イオンモール下妻店| | |
|すき家|岡山県|すき家 53号岡山IC店| | |
|すき家|岡山県|すき家 イオンモール津山店| | |
|すき家|沖縄県|すき家 イオン那覇店| | |
|すき家|岩手県|すき家 イオンモール盛岡南店| | |
|すき家|宮城県|すき家 イオンタウン佐沼店| | |
|すき家|宮城県|すき家 フォレオせんだい宮の杜店| | |
|すき家|宮城県|すき家 仙台クリスロード店|" >tmp | |
$ ./kana_han2zen.gawk tmp | |
|すき家|茨城県|すき家 イオンモール下妻店| | |
|すき家|岡山県|すき家 53号岡山IC店| | |
|すき家|岡山県|すき家 イオンモール津山店| | |
|すき家|沖縄県|すき家 イオン那覇店| | |
|すき家|岩手県|すき家 イオンモール盛岡南店| | |
|すき家|宮城県|すき家 イオンタウン佐沼店| | |
|すき家|宮城県|すき家 フォレオせんだい宮の杜店| | |
|すき家|宮城県|すき家 仙台クリスロード店| | |
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
#!/usr/bin/gawk -f | |
#gawk用 | |
#半角カナ to 全角カナ and 全角英数 to 半角英数 | |
#牛丼短観用 | |
# | |
#ex. $ ./kana_hantozen.gawk test.txt | |
#参考:http://www.geocities.jp/cygnus_odile/tategaki/script-sjis/han2zen.awk.txt | |
# | |
BEGIN{ | |
split("0123456789", az, ""); | |
split("0123456789", ah, ""); | |
split("ABCDEFGHIJKLMNOPQRSTUVWXYZ", bz, ""); | |
split("ABCDEFGHIJKLMNOPQRSTUVWXYZ", bh, ""); | |
split("・ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン", kh, ""); | |
split("・ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン", kz, ""); | |
split("ウカキクケコサシスセソタチツテトハヒフヘホ", khb, ""); #濁点可能性文字 | |
split("ヴガギグゲゴザジズゼゾダヂヅデドバビブベボ", kzd, ""); | |
split("ハヒフヘホ", hhm, ""); #半濁点可能性文字 | |
split("パピプペポ", kze, ""); | |
} | |
#main | |
{ | |
for(cnt in az) gsub(az[cnt],ah[cnt]); #全角英数to半角 | |
for(cnt in bz) gsub(bz[cnt],bh[cnt]); #全角英数to半角 | |
for(cnt in khb) gsub(khb[cnt] "゙",kzd[cnt]); #半角濁点文字to全角 | |
for(cnt in hhm) gsub(hhm[cnt] "゚",kze[cnt]); #半角パ行to全角 | |
for(cnt in kh) gsub(kh[cnt],kz[cnt]); #han2zen | |
print; #出力 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment