Showing posts with label sh. Show all posts
Showing posts with label sh. Show all posts

Tuesday, August 27, 2013

Rubyのワンライナーを使ってファイルの中で最も長い行を調べる

表題の通り、以下の処理をするワンライナー。

  • target.txtを読み込んで
  • ユニークをとって
  • 最も長い行(文字数)を調べ
  • 長い順にソートして
  • 先頭の5行を表示する

$ cat target.txt | uniq | ruby -ne 'puts sprintf("%03d %s",$_.chomp.size,$_)' | sort -r | head -5