DEV Community

teckl
teckl

Posted on • Updated on

One Liner Sample

  • Top IP (awk)
$ cat logs/access_log  | awk {'print $1'} | sort | uniq -c | sort -nr | head    
Enter fullscreen mode Exit fullscreen mode
  • Top IP (perl)
$ cat logs/access_log  | perl -lane 'print $F[0]' | sort | uniq -c | sort -nr | head
Enter fullscreen mode Exit fullscreen mode
  • Top UserAgent(awk)
$ cat logs/access_log  | awk -F '"' {'print $6'} | sort | uniq -c | sort -nr | head
Enter fullscreen mode Exit fullscreen mode
  • Top UserAgent (perl)
$ cat logs/access_log  | perl -F'"' -lane 'print $F[5]' | sort | uniq -c | sort -nr | head 
Enter fullscreen mode Exit fullscreen mode
  • minutes access count
$ cat logs/access_log  | perl -lne 'm{2017:(\d+):(\d+)} and print "$1:$2"' | sort | uniq -c | head
   6559 05:06
   5642 05:07
   5774 05:08
   5592 05:09
   4010 05:10
Enter fullscreen mode Exit fullscreen mode
  • %G format problem
$ perl -MTime::Piece -E 'say Time::Piece->strptime("2014-12-30", "%Y-%m-%d")->strftime("%Y")'
2014
$ perl -MTime::Piece -E 'say Time::Piece->strptime("2014-12-30", "%Y-%m-%d")->strftime("%G")'
2015
$ perl -MTime::Piece -E 'say Time::Piece->strptime("2014-12-28", "%Y-%m-%d")->strftime("%G")'
2014
Enter fullscreen mode Exit fullscreen mode
  • objdump version
$ objdump -s peco | perl -lanE 'm{(go/?\d.+)} and say $1' | head -1
go/1.3/libexec
Enter fullscreen mode Exit fullscreen mode
$ perl -Mojo -E 'say g("abehiroshi.la.coocan.jp")->dom->at("title")->text' | nkf -w
阿部寛のホームページ

$ perl -Mojo -E 'say g("abehiroshi.la.coocan.jp/top.htm")->dom("td")->[4]->text' | nkf -w
生年月日 1964年6月22日
Enter fullscreen mode Exit fullscreen mode

This is first test.

これはテストです🙇

Top comments (0)