wget http://standards-oui.ieee.org/oui/oui.txt
CSDN资源中心备份的当时oui文件, oui.txt 2020年2月3日内容
out.txt 文件原始内容
OUI/MA-L Organization
company_id Organization
Address
00-22-72 (hex) American Micro-Fuel Device Corp.
002272 (base 16) American Micro-Fuel Device Corp.
2181 Buchanan Loop
Ferndale WA 98248
US
00-D0-EF (hex) IGT
00D0EF (base 16) IGT
9295 PROTOTYPE DRIVE
RENO NV 89511
US
egrep "^\s+[A-Z]{2}$" oui.txt
按照设想应该可以过滤出,只包含两个大写字母的国家代码行,执行后无结果
cat -A oui.txt
猜测存在不可见字符,执行上述命令后,可见行尾包含 ^M不可见字符
OUI/MA-L Organization ^M$
company_id Organization ^M$
Address ^M$
^M$
00-22-72 (hex)^I^IAmerican Micro-Fuel Device Corp.^M$
002272 (base 16)^I^IAmerican Micro-Fuel Device Corp.^M$
^I^I^I^I2181 Buchanan Loop^M$
^I^I^I^IFerndale WA 98248^M$
^I^I^I^IUS^M$
^M$
00-D0-EF (hex)^I^IIGT^M$
00D0EF (base 16)^I^IIGT^M$
^I^I^I^I9295 PROTOTYPE DRIVE^M$
^I^I^I^IRENO NV 89511^M$
^I^I^I^IUS^M$
^M$
yum install -y dos2unix
dos2unix oui.txt
上述命令处理后可清楚^M不可见字符,参考文章如下https://www.cnblogs.com/czalinux/p/6668236.html#/c/subject/p/6668236.html
egrep "^\s+[A-Z]{2}$" oui.txt > /tmp/oui_country.txt
上述命令可以得到只包含国家代码的行,oui_country.txt文件样例
[root@test100 tmp]# vim oui_country.txt
US
US
US
US
CN
CN
CA
CA
AU
统计方法参考文章
https://stackoverflow.com/questions/10286522/group-by-sum-from-shell
准备尝试termsql方案:更具通用性、模式更符合习惯
wget https://www.python.org/ftp/python/3.8.7/Python-3.8.7.tar.xz
tar -xvf Python-3.8.7.tar.xz
yum install libffi-devel -y #termsql需要,且安装完后还需要重新编译安装Python
./configure
make
make install
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
pip3 install termsql
[root@test100 tmp]# cat oui_country.txt | termsql "SELECT col0, count(col0) c FROM tbl GROUP BY col0 order by c desc"
US|10326
CN|5401
KR|2294
TW|1975
JP|1669
统计结果可见,OUI注册量第一个的是美国,第二是中国,KR是韩国,后续可以周期性统计这个数据看看排名会不会有变化