Posts Tagged ‘cheat sheet’

python/perl/unix one liners

Friday, April 25th, 2008

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’