Python/Perl/Unix one liners

Here are some cool python one liners.

  • Parse apache log using python: print 5th field
    python -c "import csv,sys;f=csv.reader(sys.stdin, delimiter=' '); print '\n'.join([r[5] for r in f])
  • Generate frequency histogram from a text files of terms
    cat file.txt | sort | uniq -c | sort -rn
  • print 2nd column of a tab separated file
    awk -F"\t" '{print $2}'
  • perl search replace from files
    perl -i -p -e 's/old/new/g'
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments