正規表現使わず300日、知らないうちにレベル1になってました

こんにちわ。GX推進グループの平井です。

最近はとある金融商品のリプレイスのために、とある金融商品の既存システムを調査していました。
そのシステムのプログラムでどんな技術を使っているのかを機械的に知るために、ファイル名に含まれる拡張子の一覧を調べることにしました。
これの簡易版は GitHub でいうとこんなやつです。

f:id:xgxgh:20210621121841p:plain

あなたはファイルの拡張子一覧を取得するというパズルを何秒で解けますか?

やり方としては、ソースのあるディレクトリで以下のコマンドを実行するだけです。

find . -type f | sed 's!^.*/!!' | grep -o '\.[^.]*$' | sort | uniq

このコマンドでは sed や grep で正規表現を使っていますが、awk や find など正規表現を使用する場面はたくさんあります。

それでは、いくつかの GitHub リポジトリを利用して、コマンドの実行結果を見てみましょう。

github.com f:id:xgxgh:20210621130848p:plain

.cfg
.clvm
.crt
.flake8
.gitignore
.gitmodules
.hex
.idx
.ini
.json
.key
.md
.pack
.pem
.ps1
.py
.python-black
.python-lint
.sample
.sh
.sha256tree
.spec
.toml
.txt
.yaml
.yml

github.com f:id:xgxgh:20210621130824p:plain

.conf
.css
.dist
.dockerignore
.editorconfig
.eot
.gitignore
.html
.ico
.idx
.js
.json
.md
.otf
.pack
.png
.prettierignore
.ps1
.sample
.svg
.ttf
.webmanifest
.woff
.woff2
.xml
.yml

github.com f:id:xgxgh:20210621130754p:plain

.1
.ac
.am
.bash-completion
.bmp
.c
.cc
.cfg
.clang-format
.conf
.cpp
.css
.desktop
.empty
.examples
.fc
.gitattributes
.gitignore
.guess
.h
.hex
.html
.icns
.ico
.idx
.if
.in
.include
.init
.install
.java
.json
.lintian-overrides
.m4
.manpages
.md
.mk
.mm
.openrc
.openrcconf
.pack
.patch
.pem
.pgp
.plist
.png
.pro
.proto
.protocol
.py
.qrc
.raw
.rc
.s
.sage
.sample
.service
.sh
.spec
.sub
.svg
.te
.tiff
.ts
.ttf
.txt
.ui
.xpm
.yml

3つ目の実行結果で「.1なんてファイルあるのか?」と思って、調べたらちゃんとありました。

$ find . -type f -name *.1
./doc/man/dogecoin-cli.1
./doc/man/dogecoin-qt.1
./doc/man/dogecoin-tx.1
./doc/man/dogecoind.1

めでたしめでたし。

ちなみにですが、

*300*、知らないうちにレベル*になってました

でGoogle検索したりすると、面白いかもしれません。

それではまた。