LoginSignup
0
1

More than 5 years have passed since last update.

ログデータを正規化するイディオム「sort」「uniq」をよく忘れる自分のための備忘録。ついでにPythonでも同様のこと書いたメモ

Posted at

はじめに

シェルでログデータをガチャガチャする場合も時としてありますよね。
そんな時に使う[cat][sort][uniq]の熟語的なスクリプトがありますが、
よく忘れるのでここに置いときます。

それだけでは記事として面白みが薄いので、Pythonで同様のふるまいをするコードも置いときます。

シェル

重複削除の正規化
cat log.txt | sort | uniq > uniq.txt

Python

sort_uniq.py
l = [3, 3, 2, 1, 5, 1, 4, 2, 3]
l_unique = list(set(l))
print(l_unique) # [1, 2, 3, 4, 5]

思ったこと
sort->uniqやset()では、中身の順序性を保持しないのが欠点。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1