Skip to content

Instantly share code, notes, and snippets.

@ryo-murai
Last active December 25, 2018 06:31
Show Gist options
  • Save ryo-murai/a81093959ca313679cf51f5bb6edad9b to your computer and use it in GitHub Desktop.
Save ryo-murai/a81093959ca313679cf51f5bb6edad9b to your computer and use it in GitHub Desktop.
シェル芸メモ

忘れないように。というか、忘れてもいいように

  • extract Nth line
# extract 5th line from <file>
sed '5!d' $file
  • count num of specific words per lines
grep -n -o 'specific word' $file | uniq -c

# grep -n : print line number with output lines
# grep -o : show only the part of a line matching PATTERN
  • 実行例

    $ grep -w -n -o 'message' rfc2660.txt | uniq -c | sort -nr | head -10
          2 778:message
          2 760:message
          2 581:message
          2 480:message
          2 238:message
          1 828:message
          1 825:message
          1 801:message
          1 800:message
          1 799:message
  • date format

date '+%Y/%m/%d %H:%M:%S'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment